Permalink
Browse files

Add zend_make_callable() which allows to make zval's callable zval's.

At the moment this function only converts strings of the form class::method
to an array(class,method).
  • Loading branch information...
1 parent 46251fa commit 26bfe3f83a22b371fb2bf741600ab49d7ea39c04 Marcus Boerger committed Oct 25, 2003
Showing with 29 additions and 1 deletion.
  1. +28 −1 Zend/zend_API.c
  2. +1 −0 Zend/zend_API.h
View
@@ -1573,7 +1573,7 @@ ZEND_API int zend_disable_class(char *class_name, uint class_name_length TSRMLS_
return 1;
}
-zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callable_name)
+ZEND_API zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callable_name)
{
char *lcname;
zend_bool retval = 0;
@@ -1685,6 +1685,33 @@ zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callabl
}
+ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRMLS_DC)
+{
+ char *lcname, *func;
+ zend_bool retval = 0;
+
+ if (zend_is_callable(callable, 0, callable_name)) {
+ return 1;
+ }
+ switch (Z_TYPE_P(callable)) {
+ case IS_STRING:
+ lcname = zend_str_tolower_dup(Z_STRVAL_P(callable), Z_STRLEN_P(callable));
+
+ if ((func = strstr(lcname, "::")) != NULL) {
+ zval_dtor(callable);
+ array_init(callable);
+ add_next_index_stringl(callable, lcname, func - lcname, 1);
+ func += 2;
+ add_next_index_stringl(callable, func, strlen(func), 1);
+ retval = 1;
+ }
+ efree(lcname);
+ break;
+ }
+ return retval;
+}
+
+
ZEND_API char *zend_get_module_version(char *module_name)
{
zend_module_entry *module;
View
@@ -169,6 +169,7 @@ ZEND_API int zend_disable_class(char *class_name, uint class_name_length TSRMLS_
ZEND_API void zend_wrong_param_count(TSRMLS_D);
ZEND_API zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callable_name);
+ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRMLS_DC);
ZEND_API char *zend_get_module_version(char *module_name);
ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC);
ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC);

0 comments on commit 26bfe3f

Please sign in to comment.