Class: PhpEmbed::Value
- Inherits:
-
Object
- Object
- PhpEmbed::Value
- Defined in:
- ext/php_embed/value.c
Class Method Summary collapse
Instance Method Summary collapse
- #==(rhs) ⇒ Object
- #call(*args) ⇒ Object
- #callable? ⇒ Boolean
- #initialize(value) ⇒ Object constructor
- #to_a ⇒ Object
- #to_b ⇒ Object
- #to_f ⇒ Object
- #to_h ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ Object
58 59 60 61 62 63 64 |
# File 'ext/php_embed/value.c', line 58
VALUE php_value_initialize(VALUE self, VALUE value) {
zval* retval;
VALUE code;
set_zval(self, value_to_zval(value));
return Qnil;
}
|
Class Method Details
.eval(src) ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'ext/php_embed/value.c', line 140
VALUE php_value_eval(VALUE self, VALUE src) {
VALUE return_value;
char *code = StringValueCStr(src);
if (eval_and_return_php_code(code, &return_value) == FAILURE) {
rb_raise(rb_ePhpEmbedStanderdError, "eval failed");
}
return return_value;
}
|
.to_php(value) ⇒ Object
125 126 127 |
# File 'ext/php_embed/value.c', line 125
VALUE php_value_to_php(VALUE self, VALUE value) {
return convert_value_to_php_string(value);
}
|
Instance Method Details
#==(rhs) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'ext/php_embed/value.c', line 208
VALUE php_value_obj_equal(VALUE self, VALUE rhs) {
zval *lhs_zv;
zval *rhs_zv;
zval *result;
int cmp_ret;
lhs_zv = get_zval(self);
if (lhs_zv == NULL) {
return Qnil;
}
if (cPhpEmbedValue == CLASS_OF(rhs)) {
rhs_zv = get_zval(rhs);
} else {
rhs_zv = value_to_zval(rhs);
}
MAKE_STD_ZVAL(result);
compare_function(result, lhs_zv, rhs_zv TSRMLS_CC);
cmp_ret = Z_LVAL_P(result);
FREE_ZVAL(result);
return cmp_ret == 0 ? Qtrue : Qfalse;
}
|
#call(*args) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'ext/php_embed/value.c', line 78
VALUE php_value_call(int argc, VALUE *argv, VALUE self) {
char *is_callable_error;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
zval ***call_args;
zval **zval_array;
zval *retval_ptr = NULL;
int i, call_result;
VALUE args, retval;
rb_scan_args(argc, argv, "*", &args);
if (zend_fcall_info_init(get_zval(self), 0, &fci, &fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) {
VALUE err = rb_str_new2(is_callable_error);
efree(is_callable_error);
rb_raise(rb_eRuntimeError, "no callable: %s", err);
}
zval_array = (zval**)malloc(sizeof(zval*) * argc);
call_args = (zval***)malloc(sizeof(zval**) * argc);
for(i=0; i<argc; ++i) {
zval_array[i] = value_to_zval(RARRAY_PTR(args)[i]);
call_args[i] = &zval_array[i];
}
fci.retval_ptr_ptr = &retval_ptr;
fci.param_count = argc;
fci.params = call_args;
call_result = zend_call_function(&fci, &fcc TSRMLS_CC);
retval = new_php_embed_value(retval_ptr);
free(call_args);
for(i=0; i<argc-1; ++i) {
zval_dtor(zval_array[i]);
FREE_ZVAL(zval_array[i]);
}
free(zval_array);
if (FAILURE == call_result) {
rb_raise(rb_eRuntimeError, "function call fairure");
}
return retval;
}
|
#callable? ⇒ Boolean
66 67 68 69 70 71 72 73 74 75 76 |
# File 'ext/php_embed/value.c', line 66
VALUE php_value_callable(VALUE self) {
char *error;
zend_bool retval;
retval = zend_is_callable_ex(get_zval(self), NULL, 0, NULL, NULL, NULL, &error TSRMLS_CC);
if (error) {
efree(error);
}
return (retval) ? Qtrue : Qfalse;
}
|
#to_a ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'ext/php_embed/value.c', line 188
VALUE php_value_to_array(VALUE self) {
zval *zv = get_zval(self);
if (zv) {
return zval_to_array(zv);
}
return Qnil;
}
|
#to_b ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'ext/php_embed/value.c', line 173
VALUE php_value_to_boolean(VALUE self) {
zval *zv = get_zval(self);
if (zv) {
convert_to_boolean(zv);
if (Z_LVAL_P(zv)) {
return Qtrue;
} else {
return Qfalse;
}
}
return Qnil;
}
|
#to_f ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'ext/php_embed/value.c', line 162
VALUE php_value_to_float(VALUE self) {
zval *zv = get_zval(self);
if (zv) {
convert_to_double(zv);
return rb_float_new(Z_DVAL_P(zv));
}
return Qnil;
}
|
#to_h ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'ext/php_embed/value.c', line 198
VALUE php_value_to_hash(VALUE self) {
zval *zv = get_zval(self);
if (zv) {
return zval_to_hash(zv);
}
return Qnil;
}
|
#to_i ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'ext/php_embed/value.c', line 151
VALUE php_value_to_integer(VALUE self) {
zval *zv = get_zval(self);
if (zv) {
convert_to_long(zv);
return rb_fix_new(Z_LVAL_P(zv));
}
return Qnil;
}
|
#to_s ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'ext/php_embed/value.c', line 129
VALUE php_value_to_string(VALUE self) {
zval *zv = get_zval(self);
if (zv) {
convert_to_string(zv);
return rb_str_new(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
}
return Qnil;
}
|