Skip to content

Commit da68593

Browse files
committed
Use common function for autoload_list functions
1 parent 936d0ef commit da68593

File tree

1 file changed

+32
-52
lines changed

1 file changed

+32
-52
lines changed

Zend/zend_autoload.c

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,36 @@ ZEND_API void zend_register_class_autoloader(zend_fcall_info *fci, zend_fcall_in
199199
}
200200

201201
// TODO USERLAND FUNCTIONS, maybe namespace them?
202+
static void autoload_list(INTERNAL_FUNCTION_PARAMETERS, HashTable *symbol_table)
203+
{
204+
zend_autoload_func *func_info;
205+
206+
if (zend_parse_parameters_none() == FAILURE) {
207+
RETURN_THROWS();
208+
}
209+
210+
array_init(return_value);
211+
212+
ZEND_HASH_FOREACH_PTR(symbol_table, func_info) {
213+
if (Z_TYPE(func_info->fci.function_name) == IS_OBJECT) {
214+
add_next_index_zval(return_value, &func_info->fci.function_name);
215+
} else if (func_info->fcc.function_handler->common.scope) {
216+
zval tmp;
217+
218+
array_init(&tmp);
219+
if (func_info->fcc.object) {
220+
add_next_index_object(&tmp, func_info->fcc.object);
221+
} else {
222+
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.calling_scope->name));
223+
}
224+
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.function_handler->common.function_name));
225+
add_next_index_zval(return_value, &tmp);
226+
} else {
227+
add_next_index_str(return_value, zend_string_copy(func_info->fcc.function_handler->common.function_name));
228+
}
229+
} ZEND_HASH_FOREACH_END();
230+
}
231+
202232
/* Register given function as a class autoloader */
203233
ZEND_FUNCTION(autoload_register_class)
204234
{
@@ -265,32 +295,7 @@ ZEND_FUNCTION(autoload_call_class)
265295
/* Return all registered class autoloader functions */
266296
ZEND_FUNCTION(autoload_list_class)
267297
{
268-
zend_autoload_func *func_info;
269-
270-
if (zend_parse_parameters_none() == FAILURE) {
271-
RETURN_THROWS();
272-
}
273-
274-
array_init(return_value);
275-
276-
ZEND_HASH_FOREACH_PTR(&EG(autoloaders).class_autoload_functions, func_info) {
277-
if (Z_TYPE(func_info->fci.function_name) == IS_OBJECT) {
278-
add_next_index_zval(return_value, &func_info->fci.function_name);
279-
} else if (func_info->fcc.function_handler->common.scope) {
280-
zval tmp;
281-
282-
array_init(&tmp);
283-
if (func_info->fcc.object) {
284-
add_next_index_object(&tmp, func_info->fcc.object);
285-
} else {
286-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.calling_scope->name));
287-
}
288-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.function_handler->common.function_name));
289-
add_next_index_zval(return_value, &tmp);
290-
} else {
291-
add_next_index_str(return_value, zend_string_copy(func_info->fcc.function_handler->common.function_name));
292-
}
293-
} ZEND_HASH_FOREACH_END();
298+
autoload_list(INTERNAL_FUNCTION_PARAM_PASSTHRU, &EG(autoloaders).class_autoload_functions);
294299
}
295300

296301
/* Register given function as a function autoloader */
@@ -379,32 +384,7 @@ ZEND_FUNCTION(autoload_call_function)
379384
/* Return all registered function autoloader functions */
380385
ZEND_FUNCTION(autoload_list_function)
381386
{
382-
zend_autoload_func *func_info;
383-
384-
if (zend_parse_parameters_none() == FAILURE) {
385-
RETURN_THROWS();
386-
}
387-
388-
array_init(return_value);
389-
390-
ZEND_HASH_FOREACH_PTR(&EG(autoloaders).function_autoload_functions, func_info) {
391-
if (Z_TYPE(func_info->fci.function_name) == IS_OBJECT) {
392-
add_next_index_zval(return_value, &func_info->fci.function_name);
393-
} else if (func_info->fcc.function_handler->common.scope) {
394-
zval tmp;
395-
396-
array_init(&tmp);
397-
if (func_info->fcc.object) {
398-
add_next_index_object(&tmp, func_info->fcc.object);
399-
} else {
400-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.calling_scope->name));
401-
}
402-
add_next_index_str(&tmp, zend_string_copy(func_info->fcc.function_handler->common.function_name));
403-
add_next_index_zval(return_value, &tmp);
404-
} else {
405-
add_next_index_str(return_value, zend_string_copy(func_info->fcc.function_handler->common.function_name));
406-
}
407-
} ZEND_HASH_FOREACH_END();
387+
autoload_list(INTERNAL_FUNCTION_PARAM_PASSTHRU, &EG(autoloaders).function_autoload_functions);
408388
}
409389

410390
void zend_autoload_shutdown(void)

0 commit comments

Comments
 (0)