]> granicus.if.org Git - php/commitdiff
- Docu updates
authorMarcus Boerger <helly@php.net>
Sat, 8 May 2004 12:35:21 +0000 (12:35 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 8 May 2004 12:35:21 +0000 (12:35 +0000)
- Add missing example file
- Fix aggregation of inner iterators in examples

ext/spl/examples/appenditerator.inc
ext/spl/examples/infiniteiterator.inc
ext/spl/examples/regexfindfile.inc [new file with mode: 0755]
ext/spl/examples/searchiterator.inc

index df248697555689def86fb1dfb804f0f84c5bb405..edc80410df0d9bad3fd8e2a02d7ca71dbaa852b2 100755 (executable)
@@ -1,30 +1,40 @@
 <?php
 
-/**
+/** \ingroup Examples
  * @brief   Iterator that iterates over several iterators one after the other
  * @author  Marcus Boerger
  * @version 1.0
- *
  */
 class AppendIterator implements Iterator
 {
-       protected $iterators;
+       /** @internal array of inner iterators */
+       private $iterators;
 
+       /** Construct an empty AppendIterator
+        */
        function __construct()
        {
                $this->iterators = new ArrayIterator();
        }
-       
+
+       /** Append an Iterator
+        * @param $it Iterator to append
+        */     
        function append(Iterator $it)
        {
                $this->iterators->append($it);
        }
 
+       /** @return the current inner Iterator
+        */
        function getInnerIterator()
        {
                return $this->iterators->current();
        }
 
+       /** Rewind to the first element of the first inner Iterator.
+        * @return void
+        */
        function rewind()
        {
                $this->iterators->rewind();
@@ -34,11 +44,15 @@ class AppendIterator implements Iterator
                }
        }
 
+       /** @return whether the current element is valid
+         */
        function valid()
        {
                return $this->iterators->valid() && $this->getInnerIterator()->valid();
        }
 
+       /** @return the current value if it is valid or \c NULL
+        */
        function current()
        {
                /* Using $this->valid() would be exactly the same; it would omit
@@ -48,11 +62,17 @@ class AppendIterator implements Iterator
                return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL;
        }
 
+       /** @return the current key if it is valid or \c NULL
+        */
        function key()
        {
                return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL;
        }
-       
+
+       /** Move to the next element. If this means to another Iterator that 
+        * rewind that Iterator.
+        * @return void
+        */
        function next()
        {
                if (!$this->iterators->valid())
@@ -75,6 +95,13 @@ class AppendIterator implements Iterator
                        $this->iterators->next();
                }
        }
+
+       /** Aggregates the inner iterator
+        */     
+       function __call($func, $params)
+       {
+               return call_user_func_array(array($this->getInnerIterator(), $func), $params);
+       }
 }
 
 ?>
\ No newline at end of file
index ea83edb76e1f789dfafa2abb22817ee5f9e4d39c..9a3a2eca89bb846907bba7d460e9420de298d9a2 100755 (executable)
@@ -86,7 +86,7 @@ class InfiniteIterator implements Iterator
         */     
        function __call($func, $params)
        {
-               return call_user_func_array(array($this->getSubIterator(), $func), $params);
+               return call_user_func_array(array($this->it, $func), $params);
        }
 }
 
diff --git a/ext/spl/examples/regexfindfile.inc b/ext/spl/examples/regexfindfile.inc
new file mode 100755 (executable)
index 0000000..396a8ab
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * @brief   Find files by regular expression
+ * @author  Marcus Boerger
+ * @version 1.1
+ *
+ */
+class RegexFindFile extends FindFile
+{
+       /** Construct from path and regular expression
+        *
+        * @param $path the directory to search in
+        *              If path contains ';' then this parameter is split and every
+        *              part of it is used as separate directory.
+        * @param $regex perl style regular expression to find files with
+        */
+       function __construct($path, $regex)
+       {
+               parent::__construct($path, $regex);
+       }
+
+       /** @return whether the current filename matches the regular expression.
+        */
+       function accept()
+       {
+               return preg_match($this->getSearch(), $this->current());
+       }
+}
+
+?>
\ No newline at end of file
index c2bbbe6dea536a6f0607b80bd67bd6c2878862d6..caee0142dd9f4871b1ff221538b7a27b5877f9a6 100755 (executable)
@@ -42,7 +42,7 @@ abstract class SearchIterator extends FilterIterator
         */     
        function __call($func, $params)
        {
-               return call_user_func_array(array($this->getSubIterator(), $func), $params);
+               return call_user_func_array(array($this->getInnerIterator(), $func), $params);
        }
 }