From ba6c82eee9e00fee03e3c611f0802149f5dd5e56 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 11 Dec 2005 02:17:34 +0000 Subject: [PATCH] - MFH --r* switches --- sapi/cli/php.1.in | 30 +++++++++++++++++ sapi/cli/php_cli.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index fb77577353..2658b384b1 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -283,6 +283,36 @@ Arguments passed to script. Use when first argument starts with .B '\-' or script is read from stdin +.TP +.PD 0 +.B \-\-rfunction +.IR name +.TP +.PD 1 +.B \-\-rf +.IR name +Shows information about function +.B name +.TP +.PD 0 +.B \-\-rclass +.IR name +.TP +.PD 1 +.B \-\-rc +.IR name +Shows information about class +.B name +.TP +.PD 0 +.B \-\-rextension +.IR name +.TP +.PD 1 +.B \-\-re +.IR name +Shows information about extension +.B name .SH FILES .TP 15 .B php\-cli.ini diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 510aaca684..2f144285f2 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -27,6 +27,11 @@ #include "php_variables.h" #include "zend_hash.h" #include "zend_modules.h" +#include "zend_interfaces.h" + +#ifdef HAVE_REFLECTION +#include "ext/reflection/php_reflection.h" +#endif #include "SAPI.h" @@ -82,6 +87,7 @@ #include "zend_execute.h" #include "zend_highlight.h" #include "zend_indent.h" +#include "zend_exceptions.h" #include "php_getopt.h" @@ -96,6 +102,9 @@ #define PHP_MODE_STRIP 5 #define PHP_MODE_CLI_DIRECT 6 #define PHP_MODE_PROCESS_STDIN 7 +#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; @@ -129,6 +138,14 @@ static const opt_struct OPTIONS[] = { {'?', 0, "usage"},/* help alias (both '?' and 'usage') */ {'v', 0, "version"}, {'z', 1, "zend-extension"}, +#ifdef HAVE_REFLECTION + {10, 1, "rf"}, + {10, 1, "rfunction"}, + {11, 1, "rc"}, + {11, 1, "rclass"}, + {12, 1, "re"}, + {12, 1, "rextension"}, +#endif {'-', 0, NULL} /* end of args */ }; @@ -417,6 +434,10 @@ static void php_cli_usage(char *argv0) " args... Arguments passed to script. Use -- args when first argument\n" " starts with - or script is read from stdin\n" "\n" + " --rf Show information about function .\n" + " --rc Show information about class .\n" + " --re Show information about extension .\n" + "\n" , prog, prog, prog, prog, prog, prog); } /* }}} */ @@ -561,6 +582,9 @@ int main(int argc, char *argv[]) zend_file_handle file_handle; /* temporary locals */ int behavior=PHP_MODE_STANDARD; +#ifdef HAVE_REFLECTION + char *reflection_what; +#endif int orig_optind=php_optind; char *orig_optarg=php_optarg; char *arg_free=NULL, **arg_excp=&arg_free; @@ -897,6 +921,20 @@ int main(int argc, char *argv[]) hide_argv = 1; break; +#ifdef HAVE_REFLECTION + case 10: + 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; +#endif default: break; } @@ -1130,6 +1168,52 @@ int main(int argc, char *argv[]) } break; +#ifdef HAVE_REFLECTION + case PHP_MODE_REFLECTION_FUNCTION: + case PHP_MODE_REFLECTION_CLASS: + case PHP_MODE_REFLECTION_EXTENSION: + { + zend_class_entry *pce; + zval *arg, *ref; + zend_execute_data execute_data; + + switch (behavior) { + case PHP_MODE_REFLECTION_FUNCTION: + pce = reflection_function_ptr; + break; + case PHP_MODE_REFLECTION_CLASS: + pce = reflection_class_ptr; + break; + case PHP_MODE_REFLECTION_EXTENSION: + pce = reflection_extension_ptr; + break; + } + + MAKE_STD_ZVAL(arg); + ZVAL_STRING(arg, reflection_what, 1); + 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(), EG(exception), "message", sizeof("message")-1, 0 TSRMLS_CC); + zend_printf("Exception: %s\n", Z_STRVAL_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; + } +#endif /* reflection */ } } -- 2.40.0