helly           Sat Jan  3 12:20:27 2009 UTC

  Modified files:              
    /php-src/ext/reflection     php_reflection.c 
  Log:
  - Add minimalistic closure support
  
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.330&r2=1.331&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.330 
php-src/ext/reflection/php_reflection.c:1.331
--- php-src/ext/reflection/php_reflection.c:1.330       Wed Dec 31 14:37:17 2008
+++ php-src/ext/reflection/php_reflection.c     Sat Jan  3 12:20:27 2009
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_reflection.c,v 1.330 2008/12/31 14:37:17 helly Exp $ */
+/* $Id: php_reflection.c,v 1.331 2009/01/03 12:20:27 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -323,7 +323,7 @@
 /* }}} */
 
 static void _const_string(string *str, zstr name, zval *value, char *indent 
TSRMLS_DC);
-static void _function_string(string *str, zend_function *fptr, 
zend_class_entry *scope, char *indent TSRMLS_DC);
+static void _function_string(string *str, zend_function *fptr, 
zend_class_entry *scope, zval* closure, char *indent TSRMLS_DC);
 static void _property_string(string *str, zend_property_info *prop, zstr 
prop_name, char* indent TSRMLS_DC);
 static void _class_string(string *str, zend_class_entry *ce, zval *obj, char 
*indent TSRMLS_DC);
 static void _extension_string(string *str, zend_module_entry *module, char 
*indent TSRMLS_DC);
@@ -489,7 +489,7 @@
                                        && ((mptr->common.fn_flags & 
ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
                                {
                                        string_printf(str, "\n");
-                                       _function_string(str, mptr, ce, 
sub_indent.string TSRMLS_CC);
+                                       _function_string(str, mptr, ce, NULL, 
sub_indent.string TSRMLS_CC);
                                }
                                zend_hash_move_forward_ex(&ce->function_table, 
&pos);
                        }
@@ -595,7 +595,7 @@
                                                }
 
                                                string_printf(&dyn, "\n");
-                                               _function_string(&dyn, mptr, 
ce, sub_indent.string TSRMLS_CC);
+                                               _function_string(&dyn, mptr, 
ce, NULL, sub_indent.string TSRMLS_CC);
                                                count++;
                                                _free_function(closure 
TSRMLS_CC);
                                        }
@@ -767,7 +767,7 @@
 /* }}} */
 
 /* {{{ _function_string */
-static void _function_string(string *str, zend_function *fptr, 
zend_class_entry *scope, char* indent TSRMLS_DC)
+static void _function_string(string *str, zend_function *fptr, 
zend_class_entry *scope, zval* closure, char* indent TSRMLS_DC)
 {
        string param_indent;
        zend_function *overwrites;
@@ -782,7 +782,8 @@
                string_printf(str, "%s%v\n", indent, 
fptr->op_array.doc_comment.v);
        }
 
-       string_printf(str, fptr->common.scope ? "%sMethod [ " : "%sFunction [ 
", indent);
+       string_write(str, indent, strlen(indent));
+       string_printf(str, closure ? "Closure [ " : (fptr->common.scope ? 
"Method [ " : "Function [ "));
        string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : 
"<internal");
        if (fptr->common.fn_flags & ZEND_ACC_DEPRECATED) {
                string_printf(str, ", deprecated");
@@ -858,6 +859,28 @@
        }
        string_init(&param_indent);
        string_printf(&param_indent, "%s  ", indent);
+       if (closure) {
+               const zend_function *closure_fptr = 
zend_get_closure_method_def(closure TSRMLS_CC);
+               if (closure_fptr->type == ZEND_USER_FUNCTION && 
closure_fptr->op_array.static_variables) {
+                       HashTable *static_variables = 
closure_fptr->op_array.static_variables;
+                       HashPosition pos;
+                       uint key_len;
+                       zstr key;
+                       ulong num_index, index = 0;
+                       int count = zend_hash_num_elements(static_variables);
+                       if (count) {
+                               string_printf(str, "\n");
+                               string_printf(str, "%s  - Static Parameters 
[%d] {\n", indent, count);
+                               
zend_hash_internal_pointer_reset_ex(static_variables, &pos);
+                               while (index++ < count) {
+                                       
zend_hash_get_current_key_ex(static_variables, &key, &key_len, &num_index, 0, 
&pos);
+                                       string_printf(str, "%s    Parameter #%d 
[ $%v ]\n", indent, index++, key);
+                                       
zend_hash_move_forward_ex(static_variables, &pos);
+                               }       
+                               string_printf(str, "%s  }\n", indent);
+                       }
+               }
+       }
        _function_parameter_string(str, fptr, param_indent.string TSRMLS_CC);
        string_free(&param_indent);
        string_printf(str, "%s}\n", indent);
@@ -1062,7 +1085,7 @@
                                continue;
                        }
                        
-                       _function_string(str, fptr, NULL, "    " TSRMLS_CC);
+                       _function_string(str, fptr, NULL, NULL, "    " 
TSRMLS_CC);
                        func++;
                }
                string_printf(str, "%s  }\n", indent);
@@ -1465,6 +1488,7 @@
 {
        zval *name;
        zval *object;
+       zval *closure = NULL;
        unsigned int lcname_len;
        zstr lcname;
        reflection_object *intern;
@@ -1473,28 +1497,34 @@
        int name_len;
        zend_uchar type;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &name_str, 
&name_len, &type) == FAILURE) {
-               return;
-       }
-
        object = getThis();
        intern = (reflection_object *) zend_object_store_get_object(object 
TSRMLS_CC);
        if (intern == NULL) {
                return;
        }
-       lcname = zend_u_str_case_fold(type, name_str, name_len, 1, &lcname_len);
-       if (zend_u_hash_find(EG(function_table), type, lcname, lcname_len + 1, 
(void **)&fptr) == FAILURE) {
+
+       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() 
TSRMLS_CC, "O", &closure, zend_ce_closure) == SUCCESS) {
+               fptr = zend_get_closure_invoke_method(closure TSRMLS_CC);
+               Z_ADDREF_P(closure);
+       } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", 
&name_str, &name_len, &type) == SUCCESS) {
+               lcname = zend_u_str_case_fold(type, name_str, name_len, 1, 
&lcname_len);
+               if (zend_u_hash_find(EG(function_table), type, lcname, 
lcname_len + 1, (void **)&fptr) == FAILURE) {
+                       efree(lcname.v);
+                       zend_throw_exception_ex(reflection_exception_ptr, 0 
TSRMLS_CC, 
+                               "Function %R() does not exist", type, name_str);
+                       return;
+               }
                efree(lcname.v);
-               zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
-                       "Function %R() does not exist", type, name_str);
+       } else {
                return;
        }
-       efree(lcname.v);
+
        MAKE_STD_ZVAL(name);
        ZVAL_TEXT(name, fptr->common.function_name, 1);
        zend_ascii_hash_update(Z_OBJPROP_P(object), "name", sizeof("name"), 
(void **) &name, sizeof(zval *), NULL);
        intern->ptr = fptr;
        intern->ref_type = REF_TYPE_FUNCTION;
+       intern->obj = closure;
        intern->ce = NULL;
 }
 /* }}} */
@@ -1510,23 +1540,36 @@
        METHOD_NOTSTATIC_NUMPARAMS(reflection_function_abstract_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(fptr);
        string_init(&str);
-       _function_string(&str, fptr, intern->ce, "" TSRMLS_CC);
+       _function_string(&str, fptr, intern->ce, intern->obj, "" TSRMLS_CC);
        RETURN_U_STRINGL(ZEND_U_CONVERTER(UG(output_encoding_conv)), 
str.string, str.len - 1, ZSTR_AUTOFREE);
 }
 /* }}} */
 
 /* {{{ proto public string ReflectionFunction::getName() U
    Returns this function's name */
-ZEND_METHOD(reflection, function_getName)
+ZEND_METHOD(reflection_function, getName)
 {
        METHOD_NOTSTATIC_NUMPARAMS(reflection_function_abstract_ptr, 0);
        _default_get_entry(getThis(), "name", sizeof("name"), return_value 
TSRMLS_CC);
 }
 /* }}} */
 
+/* {{{ proto public bool ReflectionFunction::isClosure() U
+   Returns whether this is a closure */
+ZEND_METHOD(reflection_function, isClosure)
+{
+       reflection_object *intern;
+       zend_function *fptr;
+
+       METHOD_NOTSTATIC_NUMPARAMS(reflection_function_abstract_ptr, 0);
+       GET_REFLECTION_OBJECT_PTR(fptr);
+       RETURN_BOOL(intern->obj);
+}
+/* }}} */
+
 /* {{{ proto public bool ReflectionFunction::isInternal() U
    Returns whether this is an internal function */
-ZEND_METHOD(reflection, function_isInternal)
+ZEND_METHOD(reflection_function, isInternal)
 {
        reflection_object *intern;
        zend_function *fptr;
@@ -2468,7 +2511,7 @@
        METHOD_NOTSTATIC_NUMPARAMS(reflection_method_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(mptr);
        string_init(&str);
-       _function_string(&str, mptr, intern->ce, "" TSRMLS_CC);
+       _function_string(&str, mptr, intern->ce, intern->obj, "" TSRMLS_CC);
        RETURN_U_STRINGL(ZEND_U_CONVERTER(UG(output_encoding_conv)), 
str.string, str.len - 1, ZSTR_AUTOFREE);
 }
 /* }}} */
@@ -5013,6 +5056,7 @@
 static const zend_function_entry reflection_function_abstract_functions[] = {
        ZEND_ME(reflection, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
        PHP_ABSTRACT_ME(reflection_function, __toString, NULL)
+       ZEND_ME(reflection_function, isClosure, NULL, 0)
        ZEND_ME(reflection_function, isInternal, NULL, 0)
        ZEND_ME(reflection_function, isUserDefined, NULL, 0)
        ZEND_ME(reflection_function, getName, NULL, 0)
@@ -5438,7 +5482,7 @@
        php_info_print_table_start();
        php_info_print_table_header(2, "Reflection", "enabled");
 
-       php_info_print_table_row(2, "Version", "$Revision: 1.330 $");
+       php_info_print_table_row(2, "Version", "$Revision: 1.331 $");
 
        php_info_print_table_end();
 } /* }}} */
@@ -5452,7 +5496,7 @@
        NULL,
        NULL,
        PHP_MINFO(reflection),
-       "$Revision: 1.330 $",
+       "$Revision: 1.331 $",
        STANDARD_MODULE_PROPERTIES
 }; /* }}} */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to