]> granicus.if.org Git - php/commitdiff
- MFH --r* switches
authorMarcus Boerger <helly@php.net>
Sun, 11 Dec 2005 02:17:34 +0000 (02:17 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 11 Dec 2005 02:17:34 +0000 (02:17 +0000)
sapi/cli/php.1.in
sapi/cli/php_cli.c

index fb77577353ddd4a2be9b0318321762e3f1f7e74c..2658b384b127a355f2b837deee4189cd54ad43a8 100644 (file)
@@ -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
index 510aaca684781f9f418be16af76f33b675239273..2f144285f243f78d4a035828f12f1d6cf27e98d2 100644 (file)
 #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"
 
 #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 <name>      Show information about function <name>.\n"
+                               "  --rc <name>      Show information about class <name>.\n"
+                               "  --re <name>      Show information about extension <name>.\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 */
                        }
                }