]> granicus.if.org Git - php/commitdiff
Added missing class_uses(..) function to SPL to mirror class_implements(..).
authorStefan Marr <gron@php.net>
Sat, 23 Jul 2011 19:08:43 +0000 (19:08 +0000)
committerStefan Marr <gron@php.net>
Sat, 23 Jul 2011 19:08:43 +0000 (19:08 +0000)
# Was pointed out as missing in bug #55266.

NEWS
ext/spl/php_spl.c
ext/spl/php_spl.h
ext/spl/spl_functions.c
ext/spl/spl_functions.h

diff --git a/NEWS b/NEWS
index df2fa523a0375a05f55696ba24b23766a4fd9731..931cd67aeca5f3eb286efbe4100b42e1d8574a28 100644 (file)
--- a/NEWS
+++ b/NEWS
   . Dropped restriction of not setting the same value multiple times, the last
     one holds. (giovanni at giacobbi dot net, fat)
 
+- SPL extension:
+  . Added missing class_uses(..) as pointed out by #55266 (Stefan)
+
+
 14 Jul 2011, PHP 5.4.0 Alpha 2
 - General improvements:
   . Zend Signal Handling. (Lucas Nealan,Arnaud Le Blanc,Brian Shire, Ilia)
index de59a02c93b9cf58d75a41924c918d4041543349..8b49b6c5e1b246b23f40f3239d044479032ed069 100755 (executable)
@@ -166,6 +166,35 @@ PHP_FUNCTION(class_implements)
 }
 /* }}} */
 
+/* {{{ proto array class_uses(mixed what [, bool autoload ])
+ Return all traits used by a class. */
+PHP_FUNCTION(class_uses)
+{
+       zval *obj;
+       zend_bool autoload = 1;
+       zend_class_entry *ce;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) {
+               RETURN_FALSE;
+       }
+       if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected");
+               RETURN_FALSE;
+       }
+       
+       if (Z_TYPE_P(obj) == IS_STRING) {
+               if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) {
+                       RETURN_FALSE;
+               }
+       } else {
+               ce = Z_OBJCE_P(obj);
+       }
+       
+       array_init(return_value);
+       spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT TSRMLS_CC);
+}
+/* }}} */
+
 #define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
        spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC)
 
@@ -933,6 +962,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_implements, 0, 0, 1)
        ZEND_ARG_INFO(0, autoload)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_uses, 0, 0, 1)
+       ZEND_ARG_INFO(0, what)
+       ZEND_ARG_INFO(0, autoload)
+ZEND_END_ARG_INFO()
+
+
 ZEND_BEGIN_ARG_INFO(arginfo_spl_classes, 0)
 ZEND_END_ARG_INFO()
 
@@ -977,6 +1012,7 @@ const zend_function_entry spl_functions[] = {
        PHP_FE(spl_autoload_call,       arginfo_spl_autoload_call)
        PHP_FE(class_parents,           arginfo_class_parents)
        PHP_FE(class_implements,        arginfo_class_implements)
+  PHP_FE(class_uses,              arginfo_class_uses)
        PHP_FE(spl_object_hash,         arginfo_spl_object_hash)
 #ifdef SPL_ITERATORS_H
        PHP_FE(iterator_to_array,       arginfo_iterator_to_array)
index ee6482548a9194ad9ddfde8ae8596d7512429b1a..7c6e174e97ac77d9cc10e0af56b7d653cd24b09a 100755 (executable)
@@ -85,6 +85,7 @@ extern zend_spl_globals spl_globals;
 PHP_FUNCTION(spl_classes);
 PHP_FUNCTION(class_parents);
 PHP_FUNCTION(class_implements);
+PHP_FUNCTION(class_uses);
 
 PHPAPI void php_spl_object_hash(zval *obj, char* md5str TSRMLS_DC);
 
index 1d20b6a7f2c2c39bfa89ec9e5bcd21e2d9ddd9ae..84976bd0ad9c7c2550606e685aef1cd23319cd66 100755 (executable)
@@ -103,6 +103,18 @@ void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_fl
 }
 /* }}} */
 
+/* {{{ spl_add_traits */
+void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
+{
+       zend_uint num_traits;
+  
+       for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
+               spl_add_class_name(list, pce->traits[num_traits], allow, ce_flags TSRMLS_CC);
+       }
+}
+/* }}} */
+
+
 /* {{{ spl_add_classes */
 int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
 {
index d5e3e72670e0eae404b1111793085edda062a765..69feb3834f16c49f5f2e8be14d7457c1234ef170 100755 (executable)
@@ -62,6 +62,7 @@ void spl_register_property( zend_class_entry * class_entry, char *prop_name, int
  */
 void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
 void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
+void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
 int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC);
 
 /* caller must efree(return) */