helly           Mon Nov  1 05:45:54 2004 EDT

  Added files:                 
    /php-src/ext/spl/tests      spl_002.phpt 

  Modified files:              
    /php-src/ext/standard       array.c 
    /php-src/ext/spl    php_spl.c spl.php spl_array.c spl_array.h 
  Log:
  - Add interface Countable (PECL #30113)
  
  
http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.277&r2=1.278&ty=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.277 php-src/ext/standard/array.c:1.278
--- php-src/ext/standard/array.c:1.277  Mon Oct  4 16:17:06 2004
+++ php-src/ext/standard/array.c        Mon Nov  1 05:45:52 2004
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.277 2004/10/04 20:17:06 andi Exp $ */
+/* $Id: array.c,v 1.278 2004/11/01 10:45:52 helly Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -39,6 +39,7 @@
 #include "win32/unistd.h"
 #endif
 #include "zend_globals.h"
+#include "zend_interfaces.h"
 #include "php_globals.h"
 #include "php_array.h"
 #include "basic_functions.h"
@@ -301,13 +302,25 @@
                case IS_ARRAY:
                        RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC));
                        break;
-               case IS_OBJECT:
+               case IS_OBJECT: {
+#if HAVE_SPL
+                       zend_class_entry **pce = NULL;
+                       zval *retval;
+
+                       if (zend_lookup_class("countable", sizeof("countable")-1, &pce 
TSRMLS_CC) == SUCCESS) {
+                               zend_call_method_with_0_params(&array, NULL, NULL, 
"count", &retval);
+                               RETVAL_LONG(Z_LVAL_P(retval));
+                               zval_ptr_dtor(&retval);
+                               return;
+                       }
+#endif
                        if (Z_OBJ_HT(*array)->count_elements) {
                                RETVAL_LONG(1);
                                if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, 
&Z_LVAL_P(return_value) TSRMLS_CC)) {
                                        return;
                                }
                        }
+               }
                default:
                        RETURN_LONG(1);
                        break;
http://cvs.php.net/diff.php/php-src/ext/spl/php_spl.c?r1=1.34&r2=1.35&ty=u
Index: php-src/ext/spl/php_spl.c
diff -u php-src/ext/spl/php_spl.c:1.34 php-src/ext/spl/php_spl.c:1.35
--- php-src/ext/spl/php_spl.c:1.34      Sun Oct 31 19:26:57 2004
+++ php-src/ext/spl/php_spl.c   Mon Nov  1 05:45:53 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_spl.c,v 1.34 2004/11/01 00:26:57 helly Exp $ */
+/* $Id: php_spl.c,v 1.35 2004/11/01 10:45:53 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
        #include "config.h"
@@ -166,6 +166,7 @@
        SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CachingRecursiveIterator, z_list, sub, allow, ce_flags); \
+       SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
http://cvs.php.net/diff.php/php-src/ext/spl/spl.php?r1=1.32&r2=1.33&ty=u
Index: php-src/ext/spl/spl.php
diff -u php-src/ext/spl/spl.php:1.32 php-src/ext/spl/spl.php:1.33
--- php-src/ext/spl/spl.php:1.32        Fri Oct  1 06:35:26 2004
+++ php-src/ext/spl/spl.php     Mon Nov  1 05:45:53 2004
@@ -169,6 +169,16 @@
        function getSubIterator([$level]);
 }
 
+/** @ingroup SPL
+ * @brief This Interface allows to hook into the global count() function.
+ */
+interface Countable
+{
+       /** @return the number the global function count() should show
+        */
+       function count();
+}
+
 /** \ingroup SPL
  * \brief An Array wrapper
  *
@@ -177,7 +187,7 @@
  *
  * \see ArrayIterator
  */
-class ArrayObject implements IteratorAggregate, ArrayAccess
+class ArrayObject implements IteratorAggregate, ArrayAccess, Countable
 {
        /** Construct a new array iterator from anything that has a hash table.
         * That is any Array or Object.
@@ -239,7 +249,7 @@
  * refer to it either by using foreach or by calling its getIterator() 
  * method manually.
  */
-class ArrayIterator implements Iterator, SeekableIterator, ArrayAccess
+class ArrayIterator implements Iterator, SeekableIterator, ArrayAccess, Countable
 {
        /** Construct a new array iterator from anything that has a hash table.
         * That is any Array or Object.
http://cvs.php.net/diff.php/php-src/ext/spl/spl_array.c?r1=1.53&r2=1.54&ty=u
Index: php-src/ext/spl/spl_array.c
diff -u php-src/ext/spl/spl_array.c:1.53 php-src/ext/spl/spl_array.c:1.54
--- php-src/ext/spl/spl_array.c:1.53    Sun Oct 31 19:26:57 2004
+++ php-src/ext/spl/spl_array.c Mon Nov  1 05:45:53 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_array.c,v 1.53 2004/11/01 00:26:57 helly Exp $ */
+/* $Id: spl_array.c,v 1.54 2004/11/01 10:45:53 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -108,6 +108,10 @@
        {NULL, NULL, NULL}
 };
 
+static zend_function_entry spl_funcs_Countable[] = {
+       SPL_ABSTRACT_ME(Countable, count,   NULL)
+       {NULL, NULL, NULL}
+};
 
 zend_object_handlers spl_handler_ArrayObject;
 zend_class_entry *   spl_ce_ArrayObject;
@@ -115,6 +119,8 @@
 zend_object_handlers spl_handler_ArrayIterator;
 zend_class_entry *   spl_ce_ArrayIterator;
 
+zend_class_entry *spl_ce_Countable;
+
 typedef struct _spl_array_object {
        zend_object       std;
        zval              *array;
@@ -896,6 +902,11 @@
        memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, 
sizeof(zend_object_handlers));
        spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator;
 
+       REGISTER_SPL_INTERFACE(Countable);
+       
+       REGISTER_SPL_IMPLEMENTS(ArrayObject, Countable);
+       REGISTER_SPL_IMPLEMENTS(ArrayIterator, Countable);
+
        return SUCCESS;
 }
 /* }}} */
http://cvs.php.net/diff.php/php-src/ext/spl/spl_array.h?r1=1.10&r2=1.11&ty=u
Index: php-src/ext/spl/spl_array.h
diff -u php-src/ext/spl/spl_array.h:1.10 php-src/ext/spl/spl_array.h:1.11
--- php-src/ext/spl/spl_array.h:1.10    Sun Oct 31 19:26:57 2004
+++ php-src/ext/spl/spl_array.h Mon Nov  1 05:45:54 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_array.h,v 1.10 2004/11/01 00:26:57 helly Exp $ */
+/* $Id: spl_array.h,v 1.11 2004/11/01 10:45:54 helly Exp $ */
 
 #ifndef SPL_ARRAY_H
 #define SPL_ARRAY_H
@@ -26,6 +26,7 @@
 
 extern zend_class_entry *spl_ce_ArrayObject;
 extern zend_class_entry *spl_ce_ArrayIterator;
+extern zend_class_entry *spl_ce_Countable;
 
 PHP_MINIT_FUNCTION(spl_array);
 

http://cvs.php.net/co.php/php-src/ext/spl/tests/spl_002.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/spl_002.phpt
+++ php-src/ext/spl/tests/spl_002.phpt
--TEST--
SPL: Countable
--FILE--
<?php

class Test implements Countable
{
        function count()
        {
                return 4;
        }
};

$a = new Test;

var_dump(count($a));

?>
===DONE===
--EXPECT--
int(4)
===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to