]> granicus.if.org Git - php/commitdiff
- Rename Observer to SplObserver
authorMarcus Boerger <helly@php.net>
Thu, 15 Sep 2005 03:31:37 +0000 (03:31 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 15 Sep 2005 03:31:37 +0000 (03:31 +0000)
- Rename Subject to SplSubject
- Move SPL constants to class constants
- Update docu

22 files changed:
ext/spl/examples/directorygraphiterator.inc
ext/spl/examples/directorytreeiterator.inc
ext/spl/internal/cachingiterator.inc
ext/spl/internal/cachingrecursiveiterator.inc
ext/spl/internal/fileobject.inc
ext/spl/internal/recursivefilteriterator.inc
ext/spl/internal/recursiveiteratoriterator.inc
ext/spl/php_spl.c
ext/spl/spl.php
ext/spl/spl_array.c
ext/spl/spl_directory.c
ext/spl/spl_functions.h
ext/spl/spl_iterators.c
ext/spl/spl_observer.c
ext/spl/spl_observer.h
ext/spl/tests/array_009.phpt
ext/spl/tests/fileobject_001.phpt
ext/spl/tests/iterator_002.phpt
ext/spl/tests/iterator_023.phpt
ext/spl/tests/observer_001.phpt
ext/spl/tests/observer_002.phpt
ext/spl/tests/sxe_004.phpt

index ea31aa2b8a14dfe39e70f87bcd9d8474e914b6bf..2c417a50b0c239003e02897adca41b3781ba9192 100644 (file)
@@ -18,7 +18,7 @@ class DirectoryGraphIterator extends DirectoryTreeIterator
 {
        function __construct($path)
        {
-               RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD), 1);
+               RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1);
        }
 }
 
index 845e7fdce35eba14279351d10ea59506b18182f2..ccf8b0f28222e0b7f841e13f64c06de81ffcb3e1 100644 (file)
@@ -21,7 +21,7 @@ class DirectoryTreeIterator extends RecursiveIteratorIterator
         */
        function __construct($path)
        {
-               parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD), 1);
+               parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1);
        }
 
        /** @return the current element prefixed with ASCII graphics
index dfefd9987fcc2c0c4a37a7bfa9bea6bd2d22bb01..f5ca2c3c9df6d23bc8ef1249a0511074aff70864 100755 (executable)
@@ -9,13 +9,10 @@
  * SPL - Standard PHP Library
  */
 
-define('CIT_CALL_TOSTRING', 1);
-define('CIT_CATCH_GET_CHILD', 2);
-
 /**
  * @brief   Cached iteration over another Iterator
  * @author  Marcus Boerger
- * @version 1.1
+ * @version 1.2
  * @since PHP 5.0
  *
  * This iterator wrapper does a one ahead iteration. This way it knows whether
@@ -23,13 +20,16 @@ define('CIT_CATCH_GET_CHILD', 2);
  *
  * @note If you want to convert the elements into strings and the inner 
  *       Iterator is an internal Iterator then you need to provide the 
- *       flag CIT_CALL_TOSTRING to do the conversion when the actual element
+ *       flag CALL_TOSTRING to do the conversion when the actual element
  *       is being fetched. Otherwise the conversion would happen with the
  *       already changed iterator. If you do not need this then it you should
  *       omit this flag because it costs unneccessary work and time.
  */
 class CachingIterator implements OuterIterator
 {
+       const CALL_TOSTRING    = 1;
+       const CATCH_GET_CHILD  = 2;
+
        private $it;
        private $current;
        private $key;
@@ -40,12 +40,12 @@ class CachingIterator implements OuterIterator
         *
         * @param it    Iterator to cache
         * @param flags Bitmask: 
-        *              - CIT_CALL_TOSTRING  (whether to call __toString() for every element)
+        *              - CALL_TOSTRING  (whether to call __toString() for every element)
         */
-       function __construct(Iterator $it, $flags = CIT_CALL_TOSTRING)
+       function __construct(Iterator $it, $flags = self::CALL_TOSTRING)
        {
                $this->it = $it;
-               $this->flags = $flags & (CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD);
+               $this->flags = $flags & (self::CALL_TOSTRING|self::CATCH_GET_CHILD);
                $this->next();
        }
 
@@ -64,7 +64,7 @@ class CachingIterator implements OuterIterator
                if ($this->valid = $this->it->valid()) {
                        $this->current = $this->it->current();
                        $this->key = $this->it->key();
-                       if ($this->flags & CIT_CALL_TOSTRING) {
+                       if ($this->flags & self::CALL_TOSTRING) {
                                if (is_object($this->current)) {
                                        $this->strValue = $this->current->__toString();
                                } else {
@@ -119,11 +119,11 @@ class CachingIterator implements OuterIterator
        
        /** @return the string represenatation that was generated for the current 
         *          element
-        * @throw exception when CIT_CALL_TOSTRING was not specified in constructor
+        * @throw exception when CALL_TOSTRING was not specified in constructor
         */
        function __toString()
        {
-               if (!$this->flags & CIT_CALL_TOSTRING) {
+               if (!$this->flags & self::CALL_TOSTRING) {
                        throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
                }
                return $this->strValue;
index 72204d93992691bd5f61b29c89950e0cd3e576a2..5f60d76d5b754a285b57ffb201fb7dabf2142609 100755 (executable)
@@ -26,10 +26,10 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera
         *
         * @param it    Iterator to cache
         * @param flags Bitmask: 
-        *              - CIT_CALL_TOSTRING   (whether to call __toString() for every element)
-        *              - CIT_CATCH_GET_CHILD (whether to catch exceptions when trying to get childs)
+        *              - CALL_TOSTRING   (whether to call __toString() for every element)
+        *              - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs)
         */
-       function __construct(RecursiveIterator $it, $flags = CIT_CALL_TOSTRING)
+       function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING)
        {
                parent::__construct($it, $flags);
        }
@@ -56,7 +56,7 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera
                                $this->getChildren = new CachingRecursiveIterator($child, $this->flags);
                        }
                        catch(Exception $e) {
-                               if (!$this->flags & CIT_CATCH_GET_CHILD) {
+                               if (!$this->flags & self::CATCH_GET_CHILD) {
                                        throw $e;
                                }
                                $this->hasChildren = false;
@@ -70,7 +70,7 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera
 
        /** @return whether the current element has children
         * @note The check whether the Iterator for the children can be created was
-        *       already executed. Hence when flag CIT_CATCH_GET_CHILD was given in
+        *       already executed. Hence when flag CATCH_GET_CHILD was given in
         *       constructor this fucntion returns false so that getChildren does 
         *       not try to access those children.
         */
index a2f840a4d4b63d86d72cd13fd7d2e039870a39d2..dd2746874217c9e0bab540b513b7924043e43455 100755 (executable)
@@ -17,6 +17,9 @@
  */
 class FileObject implements RecursiveIterator, SeekableIterator
 {
+       /** Flag: wheter to suppress new lines */
+       const DROP_NEW_LINE   = 0x00000001;
+
        private $fp;
        private $fname;
        private $line     = NULL;
index ab63f8ed68e14daf17efab4c37c135e3e1932e31..b651fb20ea9598ede95beaf766f075b604b79741 100755 (executable)
@@ -13,7 +13,7 @@
  * @brief   Iterator to filter recursive iterators
  * @author  Marcus Boerger
  * @version 1.0
- * @since PHP 6.0
+ * @since PHP 5.1
  *
  * Passes the RecursiveIterator interface to the inner Iterator and provides
  * the same functionality as FilterIterator. This allows you to skip parents
index b800cd49ae09476f3da5aa959e40f7e05f9af870..61a9d60a2715c782c3af17942b69c6637c151ada 100755 (executable)
@@ -9,11 +9,6 @@
  * SPL - Standard PHP Library
  */
 
-define('RIT_LEAVES_ONLY', 0);
-define('RIT_SELF_FIRST',  1);
-define('RIT_CHILD_FIRST', 2);
-define('RIT_CATCH_GET_CHILD', 2);
-
 /**
  * @brief   Iterates through recursive iterators
  * @author  Marcus Boerger
@@ -26,25 +21,36 @@ define('RIT_CATCH_GET_CHILD', 2);
  */
 class RecursiveIteratorIterator implements OuterIterator
 {
+       /** Mode: Only show leaves */
+       const LEAVES_ONLY               = 0;
+       /** Mode: Show parents prior to their children */
+       const SELF_FIRST                = 1;
+       /** Mode: Show all children prior to their parent */
+       const CHILD_FIRST               = 2;
+
+       /** Flag: Catches exceptions during getChildren() calls and simply jumps
+        * to the next element. */
+       const CATCH_GET_CHILD   = 2;
+
        private $ait = array();
        private $count = 0;
-       private $mode  = RIT_LEAVES_ONLY;
+       private $mode  = self::LEAVES_ONLY;
        private $flags = 0;
 
        /** Construct from RecursiveIterator
         *
         * @param it     RecursiveIterator to iterate
         * @param mode   Operation mode (one of):
-        *               - RIT_LEAVES_ONLY only show leaves
-        *               - RIT_SELF_FIRST  show parents prior to their childs
-        *               - RIT_CHILD_FIRST show all childs prior to their parent
+        *               - LEAVES_ONLY only show leaves
+        *               - SELF_FIRST  show parents prior to their childs
+        *               - CHILD_FIRST show all children prior to their parent
         * @param flags  Control flags, zero or any combination of the following
         *               (since PHP 5.1).
-        *               - RIT_CATCH_GET_CHILD which catches exceptions during
+        *               - CATCH_GET_CHILD which catches exceptions during
         *                 getChildren() calls and simply jumps to the next 
         *                 element.
         */
-       function __construct(RecursiveIterator $it, $mode = RIT_LEAVES_ONLY, $flags = 0)
+       function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0)
        {
                $this->ait[0] = $it;
                $this->mode   = $mode;
@@ -61,6 +67,7 @@ class RecursiveIteratorIterator implements OuterIterator
                }
                $this->ait[0]->rewind();
                $this->ait[0]->recursed = false;
+               callNextElement(true);
        }
        
        /** @return whether iterator is valid
@@ -110,7 +117,7 @@ class RecursiveIteratorIterator implements OuterIterator
                                        }
                                        catch (Exception $e)
                                        {
-                                               if (!($this->flags & RIT_CATCH_GET_CHILD))
+                                               if (!($this->flags & self::CATCH_GET_CHILD))
                                                {
                                                        throw $e;
                                                }
@@ -140,8 +147,10 @@ class RecursiveIteratorIterator implements OuterIterator
                                unset($this->ait[$this->count--]);
                                $it = $this->ait[$this->count];
                                $this->endChildren();
+                               callNextElement(false);
                        }
                }
+               callNextElement(true);
        }
 
        /** @return Sub Iterator at given level or if unspecified the current sub 
@@ -200,6 +209,27 @@ class RecursiveIteratorIterator implements OuterIterator
        function endChildren()
        {
        }
+
+       private function callNextElement($after_move)
+       {
+               if ($this->valid())
+               {
+                       if ($after_move)
+                       {
+                               if (($this->mode == self::SELF_FIRST && $this->callHasChildren())
+                                    $this->mode == self::LEAVES_ONLY)
+                               $this->nextElement();
+                       }
+                       else
+                       {
+                               $this->nextElement();
+                       }
+               }
+       }
+       
+       /** Called when the next element is available
+        */
+       function nextElement();
 }
 
 ?>
\ No newline at end of file
index b07594c8224d6afc8388aac7b92ffb6b416d34f1..6d26785003686f38994ca939b5b46312e7774945 100755 (executable)
@@ -168,7 +168,6 @@ PHP_FUNCTION(class_implements)
        SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(LogicException, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(NoRewindIterator, z_list, sub, allow, ce_flags); \
-       SPL_ADD_CLASS(Observer, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(OutOfBoundsException, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(OutOfRangeException, z_list, sub, allow, ce_flags); \
@@ -183,7 +182,8 @@ PHP_FUNCTION(class_implements)
        SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(SimpleXMLIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(SplObjectStorage, z_list, sub, allow, ce_flags); \
-       SPL_ADD_CLASS(Subject, z_list, sub, allow, ce_flags); \
+       SPL_ADD_CLASS(SplObserver, z_list, sub, allow, ce_flags); \
+       SPL_ADD_CLASS(SplSubject, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \
 
index ba2f5dcc4a9f0554a728ef25e78b69e6a1b0350a..9b35f8386de48a399a11c1f158d38a32a202e28d 100755 (executable)
@@ -59,7 +59,7 @@
  * 
  * SPL offers an advanced XML handling class:
  * 
- * - class SimpleXMLIterator extends simplexml_element extends recursiveiterator
+ * - class SimpleXMLIterator extends simplexml_element implements RecursiveIterator
  * 
  * 4) Array Overloading
  * 
@@ -97,8 +97,9 @@
  *
  * SPL suggests a standard way of implementing the observer pattern.
  *
- * - interface Observer
- * - interface Subject
+ * - interface SplObserver
+ * - interface SplSubject
+ * - class SplObjectStorage
  * 
  * Some articles about SPL:
  * - <a href="http://www.sitepoint.com/article/php5-standard-library/1">Introducing PHP 5's Standard Library</a>
  * - <a href="http://www.phpriot.com/d/articles/php/oop/oop-with-spl-php-5-1/index.html">Advanced OOP with SPL in PHP 5</a>
  * - <a href="http://www.devshed.com/c/a/PHP/The-Standard-PHP-Library-Part-1/">The Standard PHP Library, Part 1</a>
  * - <a href="http://www.devshed.com/c/a/PHP/The-Standard-PHP-Library-Part-2/">The Standard PHP Library, Part 2</a>
+ * - <a href="http://www.wiki.cc/php/SPL">SPL on PHP Wiki</a>
+ * - <a href="http://www.professionelle-softwareentwicklung-mit-php5.de/erste_auflage/oop.iterators.spl.html">Die Standard PHP Library (SPL) [german]</a>
  *
  * Talks on SPL:
- * - <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pps">SPL for the masses [pps]</a>
- * - <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pdf">SPL for the masses [pdf]</a>
+ * - SPL for the masses <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pdf">[pdf]</a>
+ * - Debug session 1 <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_1.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_1.pdf">[pdf]</a>
+ * - Debug session 2 <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_2.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_2.pdf">[pdf]</a>
+ * - From engine overloading to SPL <a href="http://somabo.de/talks/200505_cancun_from_engine_overloading_to_spl.pps">[pps]</a>, <a href="http://somabo.de/talks/200505_cancun_from_engine_overloading_to_spl.pdf">[pdf]</a>
  *
  * You can download this documentation as a chm file 
  * <a href="http://php.net/~helly/php/ext/spl/spl.chm">here</a>.
@@ -504,6 +509,12 @@ interface Serializeable
  */
 class ArrayObject implements IteratorAggregate, ArrayAccess, Countable
 {
+       /** Properties of the object have their normal functionality
+        * when accessed as list (var_dump, foreach, etc.) */
+       const STD_PROP_LIST  = 0x00000001;
+       /** Array indices can be accessed as properties in read/write */
+       const ARRAY_AS_PROPS = 0x00000002;
+
        /** Construct a new array iterator from anything that has a hash table.
         * That is any Array or Object.
         *
@@ -588,6 +599,12 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Countable
  */
 class ArrayIterator implements SeekableIterator, ArrayAccess, Countable
 {
+       /** Properties of the object have their normal functionality
+        * when accessed as list (var_dump, foreach, etc.) */
+       const STD_PROP_LIST  = 0x00000001;
+       /** Array indices can be accessed as properties in read/write */
+       const ARRAY_AS_PROPS = 0x00000002;
+
        /** Construct a new array iterator from anything that has a hash table.
         * That is any Array or Object.
         *
index 04386ec949a22818f7fc2d58b9e20d377a10e4e6..9c80841afa4d864ad8438141b610a5e98510e82f 100755 (executable)
@@ -1236,6 +1236,11 @@ PHP_MINIT_FUNCTION(spl_array)
        REGISTER_SPL_IMPLEMENTS(ArrayObject, Countable);
        REGISTER_SPL_IMPLEMENTS(ArrayIterator, Countable);
 
+       REGISTER_SPL_CLASS_CONST_LONG(ArrayObject,   "STD_PROP_LIST",    SPL_ARRAY_STD_PROP_LIST);
+       REGISTER_SPL_CLASS_CONST_LONG(ArrayObject,   "ARRAY_AS_PROPS",   SPL_ARRAY_ARRAY_AS_PROPS);
+
+       REGISTER_SPL_CLASS_CONST_LONG(ArrayIterator, "STD_PROP_LIST",    SPL_ARRAY_STD_PROP_LIST);
+       REGISTER_SPL_CLASS_CONST_LONG(ArrayIterator, "ARRAY_AS_PROPS",   SPL_ARRAY_ARRAY_AS_PROPS);
        return SUCCESS;
 }
 /* }}} */
index 964919d97f20ae8af1ba4ca544d555dfc7e950f3..4141a489ff809d818a16630157cd84e7907358c1 100755 (executable)
@@ -1602,7 +1602,7 @@ PHP_MINIT_FUNCTION(spl_directory)
        REGISTER_SPL_IMPLEMENTS(FileObject, RecursiveIterator);
        REGISTER_SPL_IMPLEMENTS(FileObject, SeekableIterator);
 
-       REGISTER_LONG_CONSTANT("FO_DROP_NEW_LINE",  (long)SPL_FILE_OBJECT_DROP_NEW_LINE,  CONST_CS | CONST_PERSISTENT); 
+       REGISTER_SPL_CLASS_CONST_LONG(FileObject, "DROP_NEW_LINE", SPL_FILE_OBJECT_DROP_NEW_LINE);
 
        return SUCCESS;
 }
index ac39a6052880dbbcda55db1d2a8de15ad7f1be4c..2cbaedbeaa34a72548dcedb8d85b3f4119c01e82 100755 (executable)
@@ -52,6 +52,9 @@ typedef zend_object_value (*create_object_func_t)(zend_class_entry *class_type T
 #define REGISTER_SPL_PROPERTY(class_name, prop_name) \
        spl_register_property(spl_ce_ ## class_name, prop_name, prop_val, prop_flags TSRMLS_CC);
 
+#define REGISTER_SPL_CLASS_CONST_LONG(class_name, const_name, value) \
+       zend_declare_class_constant_long(spl_ce_ ## class_name, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);
+
 void spl_destroy_class(zend_class_entry ** ppce);
 
 void spl_register_std_class(zend_class_entry ** ppce, char * class_name, create_object_func_t ctor, function_entry * function_list TSRMLS_DC);
index 3f3e38652148fa439e3ea8db3bbb53d00d9ed372..0ad559089ac5a05dbc02fca242de27d3fb6f0077 100755 (executable)
@@ -93,6 +93,7 @@ typedef struct _spl_recursive_it_object {
        zend_function            *callGetChildren;
        zend_function            *beginChildren;
        zend_function            *endChildren;
+       zend_function            *nextElement;
        zend_class_entry         *ce;
 } spl_recursive_it_object;
 
@@ -209,9 +210,15 @@ next_step:
                                                }
                                        }
                                }
+                               if (object->nextElement) {
+                                       zend_call_method_with_0_params(&zthis, object->ce, &object->nextElement, "nextelement", NULL);
+                               }
                                object->iterators[object->level].state = RS_NEXT;
                                return /* self */;
                        case RS_SELF:
+                               if (object->nextElement && (object->mode == RIT_SELF_FIRST || object->mode == RIT_CHILD_FIRST)) {
+                                       zend_call_method_with_0_params(&zthis, object->ce, &object->nextElement, "nextelement", NULL);
+                               }
                                if (object->mode == RIT_SELF_FIRST) {
                                        object->iterators[object->level].state = RS_CHILD;
                                } else {
@@ -381,6 +388,10 @@ SPL_METHOD(RecursiveIteratorIterator, __construct)
        if (intern->endChildren->common.scope == U_CLASS_ENTRY(spl_ce_RecursiveIteratorIterator)) {
                intern->endChildren = NULL;
        }
+       zend_hash_find(&intern->ce->function_table, "nextelement", sizeof("nextElement"), (void **) &intern->nextElement);
+       if (intern->nextElement->common.scope == U_CLASS_ENTRY(spl_ce_RecursiveIteratorIterator)) {
+               intern->nextElement = NULL;
+       }
        ce_iterator = Z_OBJCE_P(iterator); /* respect inheritance, don't use spl_ce_RecursiveIterator */
        intern->iterators[0].iterator = ce_iterator->get_iterator(ce_iterator, iterator TSRMLS_CC);
        iterator->refcount++;
@@ -516,7 +527,9 @@ SPL_METHOD(RecursiveIteratorIterator, callGetChildren)
                return;
        } else {
                zend_call_method_with_0_params(&zobject, ce, NULL, "getchildren", &retval);
-               RETURN_ZVAL(retval, 0, 1);
+               if (retval) {
+                       RETURN_ZVAL(retval, 0, 1);
+               }
        }
 } /* }}} */
 
@@ -534,6 +547,13 @@ SPL_METHOD(RecursiveIteratorIterator, endChildren)
        /* nothing to do */
 } /* }}} */
 
+/* {{{ proto RecursiveIterator RecursiveIteratorIterator::nextElement()
+   Called when the next element is available */
+SPL_METHOD(RecursiveIteratorIterator, nextElement)
+{
+       /* nothing to do */
+} /* }}} */
+
 static union _zend_function *spl_recursive_it_get_method(zval **object_ptr, char *method, int method_len TSRMLS_DC)
 {
        union _zend_function    *function_handler;
@@ -621,6 +641,7 @@ static zend_function_entry spl_funcs_RecursiveIteratorIterator[] = {
        SPL_ME(RecursiveIteratorIterator, callGetChildren,   NULL, ZEND_ACC_PUBLIC)
        SPL_ME(RecursiveIteratorIterator, beginChildren,     NULL, ZEND_ACC_PUBLIC)
        SPL_ME(RecursiveIteratorIterator, endChildren,       NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(RecursiveIteratorIterator, nextElement,       NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
@@ -1197,6 +1218,7 @@ static zend_function_entry spl_funcs_ParentIterator[] = {
        SPL_MA(ParentIterator,  accept,           ParentIterator, hasChildren, NULL, ZEND_ACC_PUBLIC)
        SPL_ME(ParentIterator,  hasChildren,      NULL, ZEND_ACC_PUBLIC)
        SPL_ME(ParentIterator,  getChildren,      NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(dual_it,         getInnerIterator, NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
@@ -1988,13 +2010,14 @@ PHP_MINIT_FUNCTION(spl_iterators)
        spl_ce_RecursiveIteratorIterator->get_iterator = spl_recursive_it_get_iterator;
        spl_ce_RecursiveIteratorIterator->iterator_funcs.funcs = &spl_recursive_it_iterator_funcs;
 
-       REGISTER_LONG_CONSTANT("RIT_LEAVES_ONLY",     (long)RIT_LEAVES_ONLY,      CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("RIT_SELF_FIRST",      (long)RIT_SELF_FIRST,       CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("RIT_CHILD_FIRST",     (long)RIT_CHILD_FIRST,      CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("RIT_CATCH_GET_CHILD", (long)RIT_CATCH_GET_CHILD,  CONST_CS | CONST_PERSISTENT);
+       REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "LEAVES_ONLY",     RIT_LEAVES_ONLY);
+       REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "SELF_FIRST",      RIT_SELF_FIRST);
+       REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "CHILD_FIRST",     RIT_CHILD_FIRST);
+       REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "CATCH_GET_CHILD", RIT_CATCH_GET_CHILD);
 
        REGISTER_SPL_STD_CLASS_EX(FilterIterator, spl_dual_it_new, spl_funcs_FilterIterator);
        REGISTER_SPL_ITERATOR(FilterIterator);
+       spl_ce_FilterIterator->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
 
        REGISTER_SPL_SUB_CLASS_EX(RecursiveFilterIterator, FilterIterator, spl_dual_it_new, spl_funcs_RecursiveFilterIterator);
        REGISTER_SPL_IMPLEMENTS(RecursiveFilterIterator, RecursiveIterator);
@@ -2010,8 +2033,8 @@ PHP_MINIT_FUNCTION(spl_iterators)
        REGISTER_SPL_STD_CLASS_EX(CachingIterator, spl_dual_it_new, spl_funcs_CachingIterator);
        REGISTER_SPL_ITERATOR(CachingIterator);
 
-       REGISTER_LONG_CONSTANT("CIT_CALL_TOSTRING",    (long)CIT_CALL_TOSTRING,    CONST_CS | CONST_PERSISTENT); 
-       REGISTER_LONG_CONSTANT("CIT_CATCH_GET_CHILD",  (long)CIT_CATCH_GET_CHILD,  CONST_CS | CONST_PERSISTENT); 
+       REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CALL_TOSTRING",    CIT_CALL_TOSTRING); 
+       REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CATCH_GET_CHILD",  CIT_CATCH_GET_CHILD); 
 
        REGISTER_SPL_SUB_CLASS_EX(CachingRecursiveIterator, CachingIterator, spl_dual_it_new, spl_funcs_CachingRecursiveIterator);
        REGISTER_SPL_IMPLEMENTS(CachingRecursiveIterator, RecursiveIterator);
index 9975032e656e136808cdfc43b8b264479e2c372a..aa8e602a571c8406161e923e4a084aa60219710a 100755 (executable)
@@ -4,7 +4,7 @@
    +----------------------------------------------------------------------+
    | Copyright (c) 1997-2005 The PHP Group                                |
    +----------------------------------------------------------------------+
-   | This source file is subject to version 3.0 of the PHP license,       |
+   | This source file is SplSubject to version 3.0 of the PHP license,       |
    | that is bundled with this package in the file LICENSE, and is        |
    | available through the world-wide-web at the following url:           |
    | http://www.php.net/license/3_0.txt.                                  |
 #include "spl_iterators.h"
 #include "spl_array.h"
 
-SPL_METHOD(Observer, update);
-SPL_METHOD(Subject, attach);
-SPL_METHOD(Subject, detach);
-SPL_METHOD(Subject, notify);
+SPL_METHOD(SplObserver, update);
+SPL_METHOD(SplSubject, attach);
+SPL_METHOD(SplSubject, detach);
+SPL_METHOD(SplSubject, notify);
 
 static
-ZEND_BEGIN_ARG_INFO(arginfo_Observer_update, 0)
-       ZEND_ARG_OBJ_INFO(0, subject, Subject, 0)
+ZEND_BEGIN_ARG_INFO(arginfo_SplObserver_update, 0)
+       ZEND_ARG_OBJ_INFO(0, SplSubject, SplSubject, 0)
 ZEND_END_ARG_INFO();
 
-static zend_function_entry spl_funcs_Observer[] = {
-       SPL_ABSTRACT_ME(Observer, update,   arginfo_Observer_update)
+static zend_function_entry spl_funcs_SplObserver[] = {
+       SPL_ABSTRACT_ME(SplObserver, update,   arginfo_SplObserver_update)
        {NULL, NULL, NULL}
 };
 
 static
-ZEND_BEGIN_ARG_INFO(arginfo_Subject_attach, 0)
-       ZEND_ARG_OBJ_INFO(0, observer, Observer, 0)
+ZEND_BEGIN_ARG_INFO(arginfo_SplSubject_attach, 0)
+       ZEND_ARG_OBJ_INFO(0, SplObserver, SplObserver, 0)
 ZEND_END_ARG_INFO();
 
 /*static
-ZEND_BEGIN_ARG_INFO_EX(arginfo_Subject_notify, 0, 0, 1)
-       ZEND_ARG_OBJ_INFO(0, ignore, Observer, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_SplSubject_notify, 0, 0, 1)
+       ZEND_ARG_OBJ_INFO(0, ignore, SplObserver, 1)
 ZEND_END_ARG_INFO();*/
 
-static zend_function_entry spl_funcs_Subject[] = {
-       SPL_ABSTRACT_ME(Subject,  attach,   arginfo_Subject_attach)
-       SPL_ABSTRACT_ME(Subject,  detach,   arginfo_Subject_attach)
-       SPL_ABSTRACT_ME(Subject,  notify,   NULL)
+static zend_function_entry spl_funcs_SplSubject[] = {
+       SPL_ABSTRACT_ME(SplSubject,  attach,   arginfo_SplSubject_attach)
+       SPL_ABSTRACT_ME(SplSubject,  detach,   arginfo_SplSubject_attach)
+       SPL_ABSTRACT_ME(SplSubject,  notify,   NULL)
        {NULL, NULL, NULL}
 };
 
-PHPAPI zend_class_entry     *spl_ce_Observer;
-PHPAPI zend_class_entry     *spl_ce_Subject;
+PHPAPI zend_class_entry     *spl_ce_SplObserver;
+PHPAPI zend_class_entry     *spl_ce_SplSubject;
 PHPAPI zend_class_entry     *spl_ce_SplObjectStorage;
 PHPAPI zend_object_handlers spl_handler_SplObjectStorage;
 
@@ -250,8 +250,8 @@ static zend_function_entry spl_funcs_SplObjectStorage[] = {
 /* {{{ PHP_MINIT_FUNCTION(spl_observer) */
 PHP_MINIT_FUNCTION(spl_observer)
 {
-       REGISTER_SPL_INTERFACE(Observer);
-       REGISTER_SPL_INTERFACE(Subject);
+       REGISTER_SPL_INTERFACE(SplObserver);
+       REGISTER_SPL_INTERFACE(SplSubject);
 
        REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage);
        memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
index ee5f888f6da437d82007cfe484354967ec93f161..d5cf4dc6a887e640472b0f6706d351b8d0dc8327 100755 (executable)
@@ -24,8 +24,8 @@
 #include "php.h"
 #include "php_spl.h"
 
-extern PHPAPI zend_class_entry *spl_ce_Observer;
-extern PHPAPI zend_class_entry *spl_ce_Subject;
+extern PHPAPI zend_class_entry *spl_ce_SplObserver;
+extern PHPAPI zend_class_entry *spl_ce_SplSubject;
 extern PHPAPI zend_class_entry *spl_ce_SplObjectStorage;
 
 PHP_MINIT_FUNCTION(spl_observer);
index 5499caad695fa057ff781965767c6234eb4b5b13..fce2b42df29ad2ac0533b0d0a81e604f0f8c95d3 100755 (executable)
@@ -20,7 +20,7 @@ class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator
 
 $array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);
 
-$dir = new RecursiveIteratorIterator(new RecursiceArrayIterator($array), RIT_LEAVES_ONLY);
+$dir = new RecursiveIteratorIterator(new RecursiceArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY);
 
 foreach ($dir as $file) {
        print "$file\n";
index 056c1e17f71461fce7780c4440b53bd6aa977862..cfd5a74ae638eea540630b92d199ef3f5549c994 100755 (executable)
@@ -7,7 +7,7 @@ $o = new FileObject(dirname(__FILE__) . '/fileobject_001a.txt');
 
 var_dump($o->key());
 var_dump($o->current());
-$o->setFlags(FO_DROP_NEW_LINE);
+$o->setFlags(FileObject::DROP_NEW_LINE);
 var_dump($o->key());
 var_dump($o->current());
 var_dump($o->key());
@@ -32,7 +32,7 @@ foreach($o as $n => $l)
 
 echo "===B===\n";
 $o = new FileObject(dirname(__FILE__) . '/fileobject_001b.txt');
-$o->setFlags(FO_DROP_NEW_LINE);
+$o->setFlags(FileObject::DROP_NEW_LINE);
 foreach($o as $n => $l)
 {
        var_dump($n, $l);
index b481a0e00fc4a76f179c1f0558c180b1012bc1c8..d56a551c3f98922ea7e64eb8cf02c7f2a24aa562 100755 (executable)
@@ -38,7 +38,7 @@ class CrashIterator extends FilterIterator implements RecursiveIterator
 
 $array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);
 
-$dir = new RecursiveIteratorIterator(new CrashIterator(new RecursiceArrayIterator($array)), RIT_LEAVES_ONLY);
+$dir = new RecursiveIteratorIterator(new CrashIterator(new RecursiceArrayIterator($array)), RecursiveIteratorIterator::LEAVES_ONLY);
 
 foreach ($dir as $file) {
        print "$file\n";
index 46aa26ac71d559ec2c91520c05e31c530e1dd9e2..8521fa46748fb6dc342583795ef59b731682a6f2 100755 (executable)
@@ -39,7 +39,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator
        function __construct($it, $max_depth)
        {
                $this->max_depth = $max_depth;
-               parent::__construct($it, RIT_LEAVES_ONLY, RIT_CATCH_GET_CHILD);
+               parent::__construct($it, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);
        }
 
        function rewind()
index 3b20e25bdce50784a4290a1fc07a47a65ac84aa7..e7d72b9e2409cca85088816e969f3cee2273fc9e 100755 (executable)
@@ -1,9 +1,9 @@
 --TEST--
-SPL: Observer and Subject (empty notify)
+SPL: SplObserver and SplSubject (empty notify)
 --FILE--
 <?php
 
-class ObserverImpl implements Observer
+class ObserverImpl implements SplObserver
 {
        protected $name = '';
 
@@ -12,7 +12,7 @@ class ObserverImpl implements Observer
                $this->name = '$' . $name;
        }
 
-       function update(Subject $subject)
+       function update(SplSubject $subject)
        {
                echo $this->name . '->' . __METHOD__ . '(' . $subject->getName() . ");\n";
        }
@@ -23,7 +23,7 @@ class ObserverImpl implements Observer
        }
 }
 
-class SubjectImpl implements Subject
+class SubjectImpl implements SplSubject
 {
        protected $name = '';
        protected $observers = array();
@@ -33,7 +33,7 @@ class SubjectImpl implements Subject
                $this->name = '$' . $name;
        }
 
-    function attach(Observer $observer)
+    function attach(SplObserver $observer)
     {
        echo '$sub->' . __METHOD__ . '(' . $observer->getName() . ");\n";
        if (!in_array($observer, $this->observers))
@@ -42,7 +42,7 @@ class SubjectImpl implements Subject
            }
     }
 
-    function detach(Observer $observer)
+    function detach(SplObserver $observer)
     {
        echo '$sub->' . __METHOD__ . '(' . $observer->getName() . ");\n";
        $idx = array_search($observer, $this->observers);
index 3d2d930a1d65fd54472922388d61f73e94edac6b..5d006177f2e343dee638a371fb9d65f7ab47eb91 100755 (executable)
@@ -36,7 +36,7 @@ class MyObjectStorage extends SplObjectStorage
        }
 }
 
-class ObserverImpl implements Observer
+class ObserverImpl implements SplObserver
 {
        protected $name = '';
 
@@ -45,7 +45,7 @@ class ObserverImpl implements Observer
                $this->name = '$' . $name;
        }
 
-       function update(Subject $subject)
+       function update(SplSubject $subject)
        {
                echo $this->name . '->' . __METHOD__ . '(' . $subject->getName() . ");\n";
        }
@@ -56,7 +56,7 @@ class ObserverImpl implements Observer
        }
 }
 
-class SubjectImpl implements Subject
+class SubjectImpl implements SplSubject
 {
        protected $name = '';
        protected $observers;
@@ -67,13 +67,13 @@ class SubjectImpl implements Subject
                $this->name = '$' . $name;
        }
 
-       function attach(Observer $observer)
+       function attach(SplObserver $observer)
        {
                echo $this->name . '->' . __METHOD__ . '(' . $observer->getName() . ");\n";
                $this->observers->attach($observer);
        }
        
-       function detach(Observer $observer)
+       function detach(SplObserver $observer)
        {
                echo $this->name . '->' . __METHOD__ . '(' . $observer->getName() . ");\n";
                $this->observers->detach($observer);
index 3ef99514fef7cc71b05e39d863ee1757d46b147b..487de45071003f31f05ea78b339090b564333258 100755 (executable)
@@ -77,7 +77,7 @@ class SXETest extends SimpleXMLIterator
 }
 
 $sxe = new SXETest($xml);
-$rit = new RecursiveIteratorIterator($sxe, RIT_SELF_FIRST);
+$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST);
 
 foreach($rit as $data) {
        var_dump(get_class($data));