helly Sat Dec 10 08:43:56 2005 EDT
Modified files:
/php-src/sapi/cli php_cli.c
Log:
- Rewrite --r* and add --rfunction
http://cvs.php.net/diff.php/php-src/sapi/cli/php_cli.c?r1=1.139&r2=1.140&ty=u
Index: php-src/sapi/cli/php_cli.c
diff -u php-src/sapi/cli/php_cli.c:1.139 php-src/sapi/cli/php_cli.c:1.140
--- php-src/sapi/cli/php_cli.c:1.139 Mon Dec 5 20:08:40 2005
+++ php-src/sapi/cli/php_cli.c Sat Dec 10 08:43:51 2005
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli.c,v 1.139 2005/12/06 01:08:40 sniper Exp $ */
+/* $Id: php_cli.c,v 1.140 2005/12/10 13:43:51 helly Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -87,6 +87,7 @@
#include "zend_execute.h"
#include "zend_highlight.h"
#include "zend_indent.h"
+#include "zend_exceptions.h"
#include "php_getopt.h"
@@ -101,8 +102,9 @@
#define PHP_MODE_STRIP 5
#define PHP_MODE_CLI_DIRECT 6
#define PHP_MODE_PROCESS_STDIN 7
-#define PHP_MODE_REFLECTION_CLASS 8
-#define PHP_MODE_REFLECTION_EXTENSION 9
+#define PHP_MODE_REFLECTION_FUNCTION 8
+#define PHP_MODE_REFLECTION_CLASS 9
+#define PHP_MODE_REFLECTION_EXTENSION 10
static char *php_optarg = NULL;
static int php_optind = 1;
@@ -137,8 +139,9 @@
{'v', 0, "version"},
{'z', 1, "zend-extension"},
#ifdef HAVE_REFLECTION
- {10, 1, "rclass"},
- {11, 1, "rextension"},
+ {10, 1, "rfunction"},
+ {11, 1, "rclass"},
+ {12, 1, "rextension"},
#endif
{'-', 0, NULL} /* end of args */
};
@@ -922,10 +925,14 @@
#ifdef HAVE_REFLECTION
case 10:
- behavior=PHP_MODE_REFLECTION_CLASS;
+ behavior=PHP_MODE_REFLECTION_FUNCTION;
reflection_what = php_optarg;
break;
case 11:
+ behavior=PHP_MODE_REFLECTION_CLASS;
+ reflection_what = php_optarg;
+ break;
+ case 12:
behavior=PHP_MODE_REFLECTION_EXTENSION;
reflection_what = php_optarg;
break;
@@ -1164,53 +1171,47 @@
break;
#ifdef HAVE_REFLECTION
+ case PHP_MODE_REFLECTION_FUNCTION:
case PHP_MODE_REFLECTION_CLASS:
case PHP_MODE_REFLECTION_EXTENSION:
{
- zend_class_entry *reflection_ce;
- zval *arg;
-
- if (behavior ==
PHP_MODE_REFLECTION_CLASS) {
- zend_class_entry **ppce;
-
- if
(zend_lookup_class(reflection_what, strlen(reflection_what), &ppce TSRMLS_CC)
== FAILURE) {
- zend_printf("Class %s
not found\n", reflection_what);
- exit_status=254;
-
+ zend_class_entry *pce;
+ zval *arg, *ref;
+ zend_execute_data execute_data;
+
+ switch (behavior) {
+ case
PHP_MODE_REFLECTION_FUNCTION:
+ pce =
reflection_function_ptr;
break;
- }
-
- reflection_ce =
reflection_class_ptr;
- } else if (behavior ==
PHP_MODE_REFLECTION_EXTENSION) {
- char *lcname =
do_alloca(strlen(reflection_what) + 1);
- struct _zend_module_entry
*module;
-
- zend_str_tolower_copy(lcname,
reflection_what, strlen(reflection_what));
- if
(zend_hash_find(&module_registry, lcname, strlen(reflection_what) + 1, (void
**)&module) == FAILURE) {
- zend_printf("Extension
%s not found\n", reflection_what);
-
- free_alloca(lcname);
-
- exit_status=254;
+ case PHP_MODE_REFLECTION_CLASS:
+ pce =
reflection_class_ptr;
+ break;
+ case
PHP_MODE_REFLECTION_EXTENSION:
+ pce =
reflection_extension_ptr;
break;
- }
- free_alloca(lcname);
-
- reflection_ce =
reflection_extension_ptr;
- } else {
- // Can't happen
- assert(0);
- break;
}
- arg = emalloc(sizeof(zval));
- INIT_PZVAL(arg);
+ MAKE_STD_ZVAL(arg);
ZVAL_STRING(arg, reflection_what, 1);
-
- zend_call_method_with_1_params(NULL,
reflection_ce, NULL, "export", NULL, arg);
-
- zval_dtor(arg);
- FREE_ZVAL(arg);
+ ALLOC_ZVAL(ref);
+ object_init_ex(ref, pce);
+ INIT_PZVAL(ref);
+
+ memset(&execute_data, 0,
sizeof(zend_execute_data));
+ EG(current_execute_data) =
&execute_data;
+ EX(function_state).function =
pce->constructor;
+ zend_call_method_with_1_params(&ref,
pce, &pce->constructor, "__construct", NULL, arg);
+
+ if (EG(exception)) {
+ zval *msg =
zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception),
"message", sizeof("message")-1, 0 TSRMLS_CC);
+ zend_printf("Exception: %R\n",
Z_TYPE_P(msg), Z_UNIVAL_P(msg));
+ zval_ptr_dtor(&EG(exception));
+ EG(exception) = NULL;
+ } else {
+
zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, ref);
+ }
+ zval_ptr_dtor(&ref);
+ zval_ptr_dtor(&arg);
break;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php