From: Marcus Boerger Date: Sat, 25 Dec 2004 16:27:27 +0000 (+0000) Subject: - Add ReflectionClass::hasMethod() (thanks to Johannes S.) X-Git-Tag: RELEASE_0_2~468 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c7bd30a7bcaddb611660c998bcb4ce485c8070e;p=php - Add ReflectionClass::hasMethod() (thanks to Johannes S.) --- diff --git a/Zend/zend_reflection_api.c b/Zend/zend_reflection_api.c index 73da40d62e..69ee635c03 100644 --- a/Zend/zend_reflection_api.c +++ b/Zend/zend_reflection_api.c @@ -2484,6 +2484,32 @@ ZEND_METHOD(reflection_class, getConstructor) } /* }}} */ +/* {{{ proto public bool ReflectionClass::hasMethod(string name) + Returns wether a method exists or not */ +ZEND_METHOD(reflection_class, hasMethod) +{ + reflection_object *intern; + zend_class_entry *ce; + char *name, *lc_name; + int name_len; + + METHOD_NOTSTATIC; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + return; + } + + GET_REFLECTION_OBJECT_PTR(ce); + lc_name = zend_str_tolower_dup(name, name_len); + if (zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) { + efree(lc_name); + RETURN_TRUE; + } else { + efree(lc_name); + RETURN_FALSE; + } +} +/* }}} */ + /* {{{ proto public ReflectionMethod ReflectionClass::getMethod(string name) throws ReflectionException Returns the class' method specified by it's name */ ZEND_METHOD(reflection_class, getMethod) @@ -3625,6 +3651,7 @@ static zend_function_entry reflection_class_functions[] = { ZEND_ME(reflection_class, getEndLine, NULL, 0) ZEND_ME(reflection_class, getDocComment, NULL, 0) ZEND_ME(reflection_class, getConstructor, NULL, 0) + ZEND_ME(reflection_class, hasMethod, NULL, 0) ZEND_ME(reflection_class, getMethod, NULL, 0) ZEND_ME(reflection_class, getMethods, NULL, 0) ZEND_ME(reflection_class, getProperty, NULL, 0) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 73da40d62e..69ee635c03 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2484,6 +2484,32 @@ ZEND_METHOD(reflection_class, getConstructor) } /* }}} */ +/* {{{ proto public bool ReflectionClass::hasMethod(string name) + Returns wether a method exists or not */ +ZEND_METHOD(reflection_class, hasMethod) +{ + reflection_object *intern; + zend_class_entry *ce; + char *name, *lc_name; + int name_len; + + METHOD_NOTSTATIC; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + return; + } + + GET_REFLECTION_OBJECT_PTR(ce); + lc_name = zend_str_tolower_dup(name, name_len); + if (zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) { + efree(lc_name); + RETURN_TRUE; + } else { + efree(lc_name); + RETURN_FALSE; + } +} +/* }}} */ + /* {{{ proto public ReflectionMethod ReflectionClass::getMethod(string name) throws ReflectionException Returns the class' method specified by it's name */ ZEND_METHOD(reflection_class, getMethod) @@ -3625,6 +3651,7 @@ static zend_function_entry reflection_class_functions[] = { ZEND_ME(reflection_class, getEndLine, NULL, 0) ZEND_ME(reflection_class, getDocComment, NULL, 0) ZEND_ME(reflection_class, getConstructor, NULL, 0) + ZEND_ME(reflection_class, hasMethod, NULL, 0) ZEND_ME(reflection_class, getMethod, NULL, 0) ZEND_ME(reflection_class, getMethods, NULL, 0) ZEND_ME(reflection_class, getProperty, NULL, 0)