diff options
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/reflection/php_reflection.c | 188 | ||||
-rw-r--r-- | ext/reflection/php_reflection.h | 1 | ||||
-rw-r--r-- | ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt | 7 | ||||
-rw-r--r-- | sapi/cli/php.1.in | 10 | ||||
-rw-r--r-- | sapi/cli/php_cli.c | 24 |
6 files changed, 225 insertions, 7 deletions
@@ -9,6 +9,8 @@ PHP NEWS - Added FNV-1 hash support to ext/hash. (Michael Maclean) - Added ReflectionExtension::isTemporary() and ReflectionExtension::isPersistent(). (Johannes) +- Added ReflectionZendExtension class. (Johannes) +- Added command line option --rz to CLI. (Johannes) - default_charset if not specified is now UTF-8 instead of ISO-8859-1. (Rasmus) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 1315b06975..e29ea981ad 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -39,6 +39,7 @@ #include "zend_ini.h" #include "zend_interfaces.h" #include "zend_closures.h" +#include "zend_extensions.h" /* Undefine "getParameters" macro defined in "main/php3_compat.h" */ #ifdef getParameters @@ -57,6 +58,7 @@ PHPAPI zend_class_entry *reflection_object_ptr; PHPAPI zend_class_entry *reflection_method_ptr; PHPAPI zend_class_entry *reflection_property_ptr; PHPAPI zend_class_entry *reflection_extension_ptr; +PHPAPI zend_class_entry *reflection_zend_extension_ptr; #if MBO_0 ZEND_BEGIN_MODULE_GLOBALS(reflection) @@ -330,6 +332,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry static void _property_string(string *str, zend_property_info *prop, char *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); +static void _zend_extension_string(string *str, zend_extension *extension, char *indent TSRMLS_DC); /* {{{ _class_string */ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC) @@ -1112,6 +1115,26 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde } /* }}} */ +static void _zend_extension_string(string *str, zend_extension *extension, char *indent TSRMLS_DC) +{ + string_printf(str, "%sZend Extension [ %s ", indent, extension->name); + + if (extension->version) { + string_printf(str, "%s ", extension->version); + } + if (extension->copyright) { + string_printf(str, "%s ", extension->copyright); + } + if (extension->author) { + string_printf(str, "by %s ", extension->author); + } + if (extension->URL) { + string_printf(str, "<%s> ", extension->URL); + } + + string_printf(str, "]\n"); +} + /* {{{ _function_check_flag */ static void _function_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) { @@ -5046,6 +5069,148 @@ ZEND_METHOD(reflection_extension, isTemporary) } /* }}} */ +/* {{{ proto public static mixed ReflectionZendExtension::export(string name [, bool return]) throws ReflectionException + * Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ +ZEND_METHOD(reflection_zend_extension, export) +{ + _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_zend_extension_ptr, 1); +} +/* }}} */ + +/* {{{ proto public void ReflectionZendExtension::__construct(string name) + Constructor. Throws an Exception in case the given Zend extension does not exist */ +ZEND_METHOD(reflection_zend_extension, __construct) +{ + zval *name; + zval *object; + reflection_object *intern; + zend_extension *extension; + char *name_str; + int name_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) { + return; + } + + object = getThis(); + intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + if (intern == NULL) { + return; + } + + extension = zend_get_extension(name_str); + if (!extension) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + "Zend Extension %s does not exist", name_str); + return; + } + MAKE_STD_ZVAL(name); + ZVAL_STRING(name, extension->name, 1); + zend_hash_update(Z_OBJPROP_P(object), "name", sizeof("name"), (void **) &name, sizeof(zval *), NULL); + intern->ptr = extension; + intern->ref_type = REF_TYPE_OTHER; + intern->ce = NULL; +} +/* }}} */ + +/* {{{ proto public string ReflectionZendExtension::__toString() + Returns a string representation */ +ZEND_METHOD(reflection_zend_extension, __toString) +{ + reflection_object *intern; + zend_extension *extension; + string str; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(extension); + string_init(&str); + _zend_extension_string(&str, extension, "" TSRMLS_CC); + RETURN_STRINGL(str.string, str.len - 1, 0); +} +/* }}} */ + +/* {{{ proto public string ReflectionZendExtension::getName() + Returns the name of this Zend extension */ +ZEND_METHOD(reflection_zend_extension, getName) +{ + reflection_object *intern; + zend_extension *extension; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(extension); + + RETURN_STRING(extension->name, 1); +} +/* }}} */ + +/* {{{ proto public string ReflectionZendExtension::getVersion() + Returns the version information of this Zend extension */ +ZEND_METHOD(reflection_zend_extension, getVersion) +{ + reflection_object *intern; + zend_extension *extension; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(extension); + + RETURN_STRING(extension->version ? extension->version : "", 1); +} +/* }}} */ + +/* {{{ proto public void ReflectionZendExtension::getAuthor() + * Returns the name of this Zend extension's author */ +ZEND_METHOD(reflection_zend_extension, getAuthor) +{ + reflection_object *intern; + zend_extension *extension; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(extension); + + RETURN_STRING(extension->author ? extension->author : "", 1); +} +/* }}} */ + +/* {{{ proto public void ReflectionZendExtension::getURL() + Returns this Zend extension's URL*/ +ZEND_METHOD(reflection_zend_extension, getURL) +{ + reflection_object *intern; + zend_extension *extension; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(extension); + + RETURN_STRING(extension->URL ? extension->URL : "", 1); +} +/* }}} */ + +/* {{{ proto public void ReflectionZendExtension::getCopyright() + Returns this Zend extension's copyright information */ +ZEND_METHOD(reflection_zend_extension, getCopyright) +{ + reflection_object *intern; + zend_extension *extension; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(extension); + + RETURN_STRING(extension->copyright ? extension->copyright : "", 1); +} +/* }}} */ + /* {{{ method tables */ static const zend_function_entry reflection_exception_functions[] = { {NULL, NULL, NULL} @@ -5412,6 +5577,23 @@ static const zend_function_entry reflection_extension_functions[] = { ZEND_ME(reflection_extension, isTemporary, arginfo_reflection__void, 0) {NULL, NULL, NULL} }; + +ZEND_BEGIN_ARG_INFO(arginfo_reflection_zend_extension___construct, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +static const zend_function_entry reflection_zend_extension_functions[] = { + ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) + ZEND_ME(reflection_zend_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) + ZEND_ME(reflection_zend_extension, __construct, arginfo_reflection_extension___construct, 0) + ZEND_ME(reflection_zend_extension, __toString, arginfo_reflection__void, 0) + ZEND_ME(reflection_zend_extension, getName, arginfo_reflection__void, 0) + ZEND_ME(reflection_zend_extension, getVersion, arginfo_reflection__void, 0) + ZEND_ME(reflection_zend_extension, getAuthor, arginfo_reflection__void, 0) + ZEND_ME(reflection_zend_extension, getURL, arginfo_reflection__void, 0) + ZEND_ME(reflection_zend_extension, getCopyright, arginfo_reflection__void, 0) + {NULL, NULL, NULL} +}; /* }}} */ const zend_function_entry reflection_ext_functions[] = { /* {{{ */ @@ -5520,6 +5702,12 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ reflection_register_implement(reflection_extension_ptr, reflector_ptr TSRMLS_CC); zend_declare_property_string(reflection_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionZendExtension", reflection_zend_extension_functions); + _reflection_entry.create_object = reflection_objects_new; + reflection_zend_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); + reflection_register_implement(reflection_zend_extension_ptr, reflector_ptr TSRMLS_CC); + zend_declare_property_string(reflection_zend_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + return SUCCESS; } /* }}} */ diff --git a/ext/reflection/php_reflection.h b/ext/reflection/php_reflection.h index e96195792c..edca68e7a7 100644 --- a/ext/reflection/php_reflection.h +++ b/ext/reflection/php_reflection.h @@ -40,6 +40,7 @@ extern PHPAPI zend_class_entry *reflection_object_ptr; extern PHPAPI zend_class_entry *reflection_method_ptr; extern PHPAPI zend_class_entry *reflection_property_ptr; extern PHPAPI zend_class_entry *reflection_extension_ptr; +extern PHPAPI zend_class_entry *reflection_zend_extension_ptr; PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSRMLS_DC); diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt index f46c057c69..5df9e08c69 100644 --- a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt @@ -9,7 +9,7 @@ var_dump($ext->getClasses()); ?> ==DONE== --EXPECT-- -array(11) { +array(12) { ["ReflectionException"]=> &object(ReflectionClass)#2 (1) { ["name"]=> @@ -65,5 +65,10 @@ array(11) { ["name"]=> string(19) "ReflectionExtension" } + ["ReflectionZendExtension"]=> + &object(ReflectionClass)#13 (1) { + ["name"]=> + string(23) "ReflectionZendExtension" + } } ==DONE== diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in index 17346679ff..1aa1d9b794 100644 --- a/sapi/cli/php.1.in +++ b/sapi/cli/php.1.in @@ -295,6 +295,16 @@ Shows information about extension .B name .TP .PD 0 +.B \-\-rzendextension +.IR name +.TP +.PD 1 +.B \-\-rz +.IR name +Shows information about Zend extension +.B name +.TP +.PD 0 .B \-\-rextinfo .IR name .TP diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 635445e92f..37564d1372 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -117,7 +117,8 @@ PHPAPI extern char *php_ini_scanned_files; #define PHP_MODE_REFLECTION_CLASS 9 #define PHP_MODE_REFLECTION_EXTENSION 10 #define PHP_MODE_REFLECTION_EXT_INFO 11 -#define PHP_MODE_SHOW_INI_CONFIG 12 +#define PHP_MODE_REFLECTION_ZEND_EXTENSION 12 +#define PHP_MODE_SHOW_INI_CONFIG 13 const char HARDCODED_INI[] = "html_errors=0\n" @@ -165,10 +166,12 @@ static const opt_struct OPTIONS[] = { {11, 1, "rclass"}, {12, 1, "re"}, {12, 1, "rextension"}, + {13, 1, "rz"}, + {13, 1, "rzendextension"}, #endif - {13, 1, "ri"}, - {13, 1, "rextinfo"}, - {14, 0, "ini"}, + {14, 1, "ri"}, + {14, 1, "rextinfo"}, + {15, 0, "ini"}, {'-', 0, NULL} /* end of args */ }; @@ -522,6 +525,7 @@ static void php_cli_usage(char *argv0) " --rf <name> Show information about function <name>.\n" " --rc <name> Show information about class <name>.\n" " --re <name> Show information about extension <name>.\n" + " --rz <name> Show information about Zend extension <name>.\n" #endif " --ri <name> Show configuration for extension <name>.\n" "\n" @@ -1018,12 +1022,16 @@ int main(int argc, char *argv[]) behavior=PHP_MODE_REFLECTION_EXTENSION; reflection_what = php_optarg; break; -#endif case 13: - behavior=PHP_MODE_REFLECTION_EXT_INFO; + behavior=PHP_MODE_REFLECTION_ZEND_EXTENSION; reflection_what = php_optarg; break; +#endif case 14: + behavior=PHP_MODE_REFLECTION_EXT_INFO; + reflection_what = php_optarg; + break; + case 15: behavior = PHP_MODE_SHOW_INI_CONFIG; break; default: @@ -1288,6 +1296,7 @@ int main(int argc, char *argv[]) case PHP_MODE_REFLECTION_FUNCTION: case PHP_MODE_REFLECTION_CLASS: case PHP_MODE_REFLECTION_EXTENSION: + case PHP_MODE_REFLECTION_ZEND_EXTENSION: { zend_class_entry *pce = NULL; zval *arg, *ref; @@ -1309,6 +1318,9 @@ int main(int argc, char *argv[]) case PHP_MODE_REFLECTION_EXTENSION: pce = reflection_extension_ptr; break; + case PHP_MODE_REFLECTION_ZEND_EXTENSION: + pce = reflection_zend_extension_ptr; + break; } MAKE_STD_ZVAL(arg); |