]> granicus.if.org Git - php/commitdiff
- Add ReclectionClass:hasProperty(), ReflectionClass::hasConstant()
authorMarcus Boerger <helly@php.net>
Mon, 31 Jan 2005 22:56:01 +0000 (22:56 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 31 Jan 2005 22:56:01 +0000 (22:56 +0000)
  to complete api (johannes@php.net)

Zend/zend_reflection_api.c
ext/reflection/php_reflection.c

index 071bfec5536d6cff278c0b37bbfc4c24d024de9c..75ef5917a3bbd9a83efd592990b1b3d5fa010dee 100644 (file)
@@ -2581,6 +2581,29 @@ ZEND_METHOD(reflection_class, getMethods)
 }
 /* }}} */
 
+/* {{{ proto public bool ReflectionClass::hasProperty(string name)
+   Returns wether a property exists or not */
+ZEND_METHOD(reflection_class, hasProperty)
+{
+       reflection_object *intern;
+       zend_class_entry *ce;
+       char *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);
+       if (zend_hash_exists(&ce->properties_info, name, name_len + 1)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
 /* {{{ proto public ReflectionProperty ReflectionClass::getProperty(string name) throws ReflectionException
    Returns the class' property specified by it's name */
 ZEND_METHOD(reflection_class, getProperty)
@@ -2651,6 +2674,29 @@ ZEND_METHOD(reflection_class, getProperties)
 }
 /* }}} */
 
+/* {{{ proto public bool ReflectionClass::hasConstant(string name)
+   Returns wether a constant exists or not */
+ZEND_METHOD(reflection_class, hasConstant)
+{
+       reflection_object *intern;
+       zend_class_entry *ce;
+       char *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);
+       if (zend_hash_exists(&ce->constants_table, name, name_len + 1)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
 /* {{{ proto public array ReflectionClass::getConstants()
    Returns an associative array containing this class' constants and their values */
 ZEND_METHOD(reflection_class, getConstants)
@@ -3653,8 +3699,10 @@ static zend_function_entry reflection_class_functions[] = {
        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, hasProperty, NULL, 0)
        ZEND_ME(reflection_class, getProperty, NULL, 0)
        ZEND_ME(reflection_class, getProperties, NULL, 0)
+       ZEND_ME(reflection_class, hasConstant, NULL, 0)
        ZEND_ME(reflection_class, getConstants, NULL, 0)
        ZEND_ME(reflection_class, getConstant, NULL, 0)
        ZEND_ME(reflection_class, getInterfaces, NULL, 0)
index 071bfec5536d6cff278c0b37bbfc4c24d024de9c..75ef5917a3bbd9a83efd592990b1b3d5fa010dee 100644 (file)
@@ -2581,6 +2581,29 @@ ZEND_METHOD(reflection_class, getMethods)
 }
 /* }}} */
 
+/* {{{ proto public bool ReflectionClass::hasProperty(string name)
+   Returns wether a property exists or not */
+ZEND_METHOD(reflection_class, hasProperty)
+{
+       reflection_object *intern;
+       zend_class_entry *ce;
+       char *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);
+       if (zend_hash_exists(&ce->properties_info, name, name_len + 1)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
 /* {{{ proto public ReflectionProperty ReflectionClass::getProperty(string name) throws ReflectionException
    Returns the class' property specified by it's name */
 ZEND_METHOD(reflection_class, getProperty)
@@ -2651,6 +2674,29 @@ ZEND_METHOD(reflection_class, getProperties)
 }
 /* }}} */
 
+/* {{{ proto public bool ReflectionClass::hasConstant(string name)
+   Returns wether a constant exists or not */
+ZEND_METHOD(reflection_class, hasConstant)
+{
+       reflection_object *intern;
+       zend_class_entry *ce;
+       char *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);
+       if (zend_hash_exists(&ce->constants_table, name, name_len + 1)) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
 /* {{{ proto public array ReflectionClass::getConstants()
    Returns an associative array containing this class' constants and their values */
 ZEND_METHOD(reflection_class, getConstants)
@@ -3653,8 +3699,10 @@ static zend_function_entry reflection_class_functions[] = {
        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, hasProperty, NULL, 0)
        ZEND_ME(reflection_class, getProperty, NULL, 0)
        ZEND_ME(reflection_class, getProperties, NULL, 0)
+       ZEND_ME(reflection_class, hasConstant, NULL, 0)
        ZEND_ME(reflection_class, getConstants, NULL, 0)
        ZEND_ME(reflection_class, getConstant, NULL, 0)
        ZEND_ME(reflection_class, getInterfaces, NULL, 0)