Skip to content

Commit 6d49c93

Browse files
committed
Prepare for returning ReflectionAttribute not array.
1 parent 9a2b506 commit 6d49c93

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

ext/reflection/php_reflection.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,21 @@ typedef struct _type_reference {
133133
zend_bool legacy_behavior;
134134
} type_reference;
135135

136+
/* Struct for attributes */
137+
typedef struct _attribute_reference {
138+
zend_string *name;
139+
zval *arguments;
140+
} attribute_reference;
141+
136142
typedef enum {
137143
REF_TYPE_OTHER, /* Must be 0 */
138144
REF_TYPE_FUNCTION,
139145
REF_TYPE_GENERATOR,
140146
REF_TYPE_PARAMETER,
141147
REF_TYPE_TYPE,
142148
REF_TYPE_PROPERTY,
143-
REF_TYPE_CLASS_CONSTANT
149+
REF_TYPE_CLASS_CONSTANT,
150+
REF_TYPE_ATTRIBUTE
144151
} reflection_type_t;
145152

146153
/* Struct for reflection objects */
@@ -221,6 +228,7 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
221228
reflection_object *intern = reflection_object_from_obj(object);
222229
parameter_reference *reference;
223230
property_reference *prop_reference;
231+
attribute_reference *attr_reference;
224232

225233
if (intern->ptr) {
226234
switch (intern->ref_type) {
@@ -246,6 +254,10 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
246254
zend_string_release_ex(prop_reference->unmangled_name, 0);
247255
efree(intern->ptr);
248256
break;
257+
case REF_TYPE_ATTRIBUTE:
258+
attr_reference = (attribute_reference*)intern->ptr;
259+
efree(attr_reference);
260+
break;
249261
case REF_TYPE_GENERATOR:
250262
case REF_TYPE_CLASS_CONSTANT:
251263
case REF_TYPE_OTHER:
@@ -1179,6 +1191,22 @@ static void reflection_type_factory(zend_type type, zval *object, zend_bool lega
11791191
}
11801192
/* }}} */
11811193

1194+
/* {{{ reflection_attribute_factory */
1195+
static void reflection_attribute_factory(zval *object, zend_string *name, zval *arguments)
1196+
{
1197+
reflection_object *intern;
1198+
attribute_reference *reference;
1199+
1200+
reflection_instantiate(reflection_attribute_ptr, object);
1201+
intern = Z_REFLECTION_P(object);
1202+
reference = (attribute_reference*) emalloc(sizeof(attribute_reference));
1203+
reference->name = name;
1204+
reference->arguments = arguments;
1205+
intern->ptr = reference;
1206+
intern->ref_type = REF_TYPE_ATTRIBUTE;
1207+
}
1208+
/* }}} */
1209+
11821210
/* {{{ reflection_function_factory */
11831211
static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object)
11841212
{
@@ -3646,7 +3674,7 @@ ZEND_METHOD(reflection_class_constant, getAttributes)
36463674
}
36473675
GET_REFLECTION_OBJECT_PTR(ref);
36483676
if (ref->attributes) {
3649-
zend_ast_convert_attributes(return_value, ref->attributes, NULL);
3677+
zend_ast_convert_attributes(return_value, ref->attributes, ref->ce);
36503678
} else {
36513679
array_init(return_value);
36523680
}
@@ -4027,7 +4055,7 @@ ZEND_METHOD(reflection_class, getAttributes)
40274055
}
40284056
GET_REFLECTION_OBJECT_PTR(ce);
40294057
if (ce->type == ZEND_USER_CLASS && ce->info.user.attributes) {
4030-
zend_ast_convert_attributes(return_value, ce->info.user.attributes, NULL);
4058+
zend_ast_convert_attributes(return_value, ce->info.user.attributes, ce);
40314059
} else {
40324060
array_init(return_value);
40334061
}
@@ -5545,7 +5573,7 @@ ZEND_METHOD(reflection_property, getAttributes)
55455573
}
55465574
GET_REFLECTION_OBJECT_PTR(ref);
55475575
if (ref->prop->attributes) {
5548-
zend_ast_convert_attributes(return_value, ref->prop->attributes, NULL);
5576+
zend_ast_convert_attributes(return_value, ref->prop->attributes, ref->prop->ce);
55495577
} else {
55505578
array_init(return_value);
55515579
}

0 commit comments

Comments
 (0)