@@ -84,6 +84,79 @@ zend_object_handlers* phongo_get_std_object_handlers(void);
8484 } \
8585 } while (0)
8686
87+ #define PHONGO_GET_PROPERTY_HANDLERS (_name , _intern_extractor ) \
88+ static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \
89+ { \
90+ HashTable *props = _intern_extractor(zobj)->php_properties; \
91+ if (!props) { \
92+ ALLOC_HASHTABLE(props); \
93+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
94+ _intern_extractor(zobj)->php_properties = props; \
95+ } \
96+ return zend_hash_find(props, member); \
97+ } \
98+ \
99+ static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \
100+ { \
101+ Z_TRY_ADDREF_P(value); \
102+ HashTable *props = _intern_extractor(zobj)->php_properties; \
103+ if (!props) { \
104+ ALLOC_HASHTABLE(props); \
105+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
106+ _intern_extractor(zobj)->php_properties = props; \
107+ } \
108+ return zend_hash_add_new(props, name, value); \
109+ } \
110+ static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \
111+ { \
112+ HashTable *props = _intern_extractor(zobj)->php_properties; \
113+ if (!props) { \
114+ ALLOC_HASHTABLE(props); \
115+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
116+ _intern_extractor(zobj)->php_properties = props; \
117+ } \
118+ zval *value = zend_hash_find(props, name); \
119+ if (value) { \
120+ if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \
121+ return zend_is_true(value); \
122+ } \
123+ if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \
124+ ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \
125+ ZVAL_DEREF(value); \
126+ return (Z_TYPE_P(value) != IS_NULL); \
127+ } \
128+ ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \
129+ return true; \
130+ } \
131+ return false; \
132+ } \
133+ static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \
134+ { \
135+ HashTable *props = _intern_extractor(zobj)->php_properties; \
136+ if (!props) { \
137+ ALLOC_HASHTABLE(props); \
138+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
139+ _intern_extractor(zobj)->php_properties = props; \
140+ } \
141+ zend_hash_del(props, name); \
142+ } \
143+ \
144+ static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \
145+ { \
146+ HashTable *props = _intern_extractor(zobj)->php_properties; \
147+ if (!props) { \
148+ ALLOC_HASHTABLE(props); \
149+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
150+ _intern_extractor(zobj)->php_properties = props; \
151+ } \
152+ \
153+ zval *value = zend_hash_find(props, name); \
154+ if (value) { \
155+ return value; \
156+ } \
157+ return zend_hash_add(props, name, &EG(uninitialized_zval)); \
158+ }
159+
87160#define PHONGO_ZVAL_EXCEPTION_NAME (e ) (ZSTR_VAL(e->ce->name))
88161
89162#define PHONGO_SET_CREATED_BY_PID (intern ) \
0 commit comments