5 php_http_property_proxy_t
*php_http_property_proxy_init(php_http_property_proxy_t
*proxy
, zval
*object
, zval
*member TSRMLS_DC
)
8 proxy
= emalloc(sizeof(*proxy
));
10 memset(proxy
, 0, sizeof(*proxy
));
12 MAKE_STD_ZVAL(proxy
->myself
);
13 ZVAL_OBJVAL(proxy
->myself
, php_http_property_proxy_object_new_ex(php_http_property_proxy_class_entry
, proxy
, NULL TSRMLS_CC
), 0);
15 proxy
->object
= object
;
16 proxy
->member
= php_http_ztyp(IS_STRING
, member
);
21 void php_http_property_proxy_dtor(php_http_property_proxy_t
*proxy
)
23 zval_ptr_dtor(&proxy
->object
);
24 zval_ptr_dtor(&proxy
->member
);
25 zval_ptr_dtor(&proxy
->myself
);
28 void php_http_property_proxy_free(php_http_property_proxy_t
**proxy
)
31 php_http_property_proxy_dtor(*proxy
);
38 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpPropertyProxy, method, 0, req_args)
39 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpPropertyProxy, method, 0)
40 #define PHP_HTTP_PP_ME(method, visibility) PHP_ME(HttpPropertyProxy, method, PHP_HTTP_ARGS(HttpPropertyProxy, method), visibility)
42 PHP_HTTP_EMPTY_ARGS(__construct
);
44 zend_class_entry
*php_http_property_proxy_class_entry
;
45 zend_function_entry php_http_property_proxy_method_entry
[] = {
46 PHP_HTTP_PP_ME(__construct
, ZEND_ACC_FINAL
|ZEND_ACC_PRIVATE
)
49 static zend_object_handlers php_http_property_proxy_object_handlers
;
51 zend_object_value
php_http_property_proxy_object_new(zend_class_entry
*ce TSRMLS_DC
)
53 return php_http_property_proxy_object_new_ex(ce
, NULL
, NULL TSRMLS_CC
);
56 zend_object_value
php_http_property_proxy_object_new_ex(zend_class_entry
*ce
, php_http_property_proxy_t
*proxy
, php_http_property_proxy_object_t
**ptr TSRMLS_DC
)
59 php_http_property_proxy_object_t
*o
;
61 o
= ecalloc(1, sizeof(*o
));
62 zend_object_std_init((zend_object
*) o
, ce TSRMLS_CC
);
63 object_properties_init((zend_object
*) o
, ce
);
70 ov
.handle
= zend_objects_store_put(o
, NULL
, php_http_property_proxy_object_free
, NULL TSRMLS_CC
);
71 ov
.handlers
= &php_http_property_proxy_object_handlers
;
76 void php_http_property_proxy_object_free(void *object TSRMLS_DC
)
78 php_http_property_proxy_object_t
*o
= object
;
81 php_http_property_proxy_free(&o
->proxy
);
83 zend_object_std_dtor((zend_object
*) o TSRMLS_CC
);
87 static void php_http_property_proxy_object_set(zval
**object
, zval
*value TSRMLS_DC
)
89 php_http_property_proxy_object_t
*obj
= zend_object_store_get_object(*object TSRMLS_CC
);
91 zend_update_property(Z_OBJCE_P(obj
->proxy
->object
), obj
->proxy
->object
, Z_STRVAL_P(obj
->proxy
->member
), Z_STRLEN_P(obj
->proxy
->member
), value TSRMLS_CC
);
94 static zval
*php_http_property_proxy_object_get(zval
*object TSRMLS_DC
)
96 php_http_property_proxy_object_t
*obj
= zend_object_store_get_object(object TSRMLS_CC
);
98 return zend_read_property(Z_OBJCE_P(obj
->proxy
->object
), obj
->proxy
->object
, Z_STRVAL_P(obj
->proxy
->member
), Z_STRLEN_P(obj
->proxy
->member
), 0 TSRMLS_CC
);
101 static STATUS
php_http_property_proxy_object_cast(zval
*object
, zval
*return_value
, int type TSRMLS_DC
)
103 zval
*old_value
, *new_value
;
105 old_value
= php_http_property_proxy_object_get(object TSRMLS_CC
);
106 new_value
= php_http_ztyp(type
, old_value
);
108 if (old_value
!= new_value
) {
109 zval_ptr_dtor(&old_value
);
112 RETVAL_ZVAL(new_value
, 0, 0);
117 static zval
*php_http_property_proxy_object_read_dimension(zval
*object
, zval
*offset
, int type TSRMLS_DC
)
119 zval
*retval
= NULL
, *property
= php_http_property_proxy_object_get(object TSRMLS_CC
);
121 if (Z_TYPE_P(property
) == IS_ARRAY
) {
124 if (Z_TYPE_P(offset
) == IS_LONG
) {
125 if (SUCCESS
== zend_hash_index_find(Z_ARRVAL_P(property
), Z_LVAL_P(offset
), (void *) &data
)) {
129 offset
= php_http_ztyp(IS_STRING
, offset
);
130 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(property
), Z_STRVAL_P(offset
), Z_STRLEN_P(offset
), (void *) &data
)) {
133 zval_ptr_dtor(&offset
);
140 zval_ptr_dtor(&property
);
145 static void php_http_property_proxy_object_write_dimension(zval
*object
, zval
*offset
, zval
*value TSRMLS_DC
)
147 zval
*property
= php_http_property_proxy_object_get(object TSRMLS_CC
);
149 switch (Z_TYPE_P(property
)) {
151 array_init(property
);
155 add_next_index_zval(property
, value
);
156 } else if (Z_TYPE_P(offset
) == IS_LONG
) {
157 add_index_zval(property
, Z_LVAL_P(offset
), value
);
159 offset
= php_http_ztyp(IS_STRING
, offset
);
160 add_assoc_zval_ex(property
, Z_STRVAL_P(offset
), Z_STRLEN_P(offset
) + 1, value
);
161 zval_ptr_dtor(&offset
);
163 php_http_property_proxy_object_set(&object
, property TSRMLS_CC
);
167 zval_ptr_dtor(&property
);
172 PHP_METHOD(HttpPropertyProxy
, __construct
)
176 PHP_MINIT_FUNCTION(http_property_proxy
)
178 PHP_HTTP_REGISTER_CLASS(http
\\object
, PropertyProxy
, http_property_proxy
, NULL
, ZEND_ACC_FINAL
);
179 php_http_property_proxy_class_entry
->create_object
= php_http_property_proxy_object_new
;
180 memcpy(&php_http_property_proxy_object_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
181 php_http_property_proxy_object_handlers
.set
= php_http_property_proxy_object_set
;
182 php_http_property_proxy_object_handlers
.get
= php_http_property_proxy_object_get
;
183 php_http_property_proxy_object_handlers
.cast_object
= php_http_property_proxy_object_cast
;
184 php_http_property_proxy_object_handlers
.read_dimension
= php_http_property_proxy_object_read_dimension
;
185 php_http_property_proxy_object_handlers
.write_dimension
= php_http_property_proxy_object_write_dimension
;