helly           Sat May  8 08:24:15 2004 EDT

  Added files:                 
    /php-src/ext/spl/internal   cachingiterator.inc 
                                cachingrecursiveiterator.inc 
                                filteriterator.inc limititerator.inc 
                                parentiterator.inc recursiveiterator.inc 
                                recursiveiteratoriterator.inc 
                                seekableiterator.inc 
    /php-src/ext/spl/examples   dbaarray.inc dbareader.inc inigroups.inc 
                                keyfilter.inc 

  Removed files:               
    /php-src/ext/spl/examples   IniGroups.inc KeyFilter.inc 
                                cachingiterator.inc 
                                cachingrecursiveiterator.inc 
                                dba_reader.inc directorygraphiterator.inc 
                                filteriterator.inc limititerator.inc 
                                parentiterator.inc recursiveiterator.inc 
                                recursiveiteratoriterator.inc 
                                seekableiterator.inc 

  Modified files:              
    /php-src/ext/spl/examples   autoload.inc dba_array.php dba_dump.php 
                                directoryfilterdots.inc directorytree.inc 
                                directorytreeiterator.inc 
                                emptyiterator.inc findfile.inc 
                                findregex.php infiniteiterator.inc 
                                ini_groups.php searchiterator.inc 
                                tree.php 
  Log:
  - Update examples
  - Update documentation
  - Move classes/interfaces already implemented in c to new subdir internal
  
  
http://cvs.php.net/diff.php/php-src/ext/spl/examples/autoload.inc?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/spl/examples/autoload.inc
diff -u php-src/ext/spl/examples/autoload.inc:1.3 
php-src/ext/spl/examples/autoload.inc:1.4
--- php-src/ext/spl/examples/autoload.inc:1.3   Sun May  2 18:55:22 2004
+++ php-src/ext/spl/examples/autoload.inc       Sat May  8 08:24:15 2004
@@ -1,5 +1,8 @@
 <?php
 
+/** \internal
+ * Tries to load class $classname from directory $dir.
+ */
 function __load_class($classname, $dir)
 {
        $file = $dir . '/' . $classname . '.inc';
@@ -11,6 +14,14 @@
        return false;
 }
 
+/** 
+ * @brief   Class loader for SPL example classes
+ * @author  Marcus Boerger
+ * @version 1.0
+ *
+ * Loads classes automatically from include_path as given by ini or from
+ * current directory of script or include file.
+ */
 function __autoload($classname) {
        $classname = strtolower($classname);
        foreach(split(':', ini_get('include_path')) as $dir)
http://cvs.php.net/diff.php/php-src/ext/spl/examples/dba_array.php?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/spl/examples/dba_array.php
diff -u php-src/ext/spl/examples/dba_array.php:1.3 
php-src/ext/spl/examples/dba_array.php:1.4
--- php-src/ext/spl/examples/dba_array.php:1.3  Thu Dec  4 14:39:46 2003
+++ php-src/ext/spl/examples/dba_array.php      Sat May  8 08:24:15 2004
@@ -9,7 +9,7 @@
  *
  * Note: configure with --enable-dba 
  *
- * (c) Marcus Boerger, 2003
+ * (c) Marcus Boerger, 2003 - 2004
  */
 
 if ($argc < 4) {
@@ -24,55 +24,7 @@
        exit(1);
 }
 
-class DbaArray implements ArrayAccess {
-       private $db;
-
-       function __construct($file, $handler)
-       {
-               $this->db = dba_popen($file, "c", $handler);
-               if (!$this->db) {
-                       throw new exception("Databse could not be opened");
-               }
-       }
-
-       function __destruct()
-       {
-               dba_close($this->db);
-       }
-
-       function get($name)
-       {
-               $data = dba_fetch($name, $this->db); 
-               if($data) {
-                       if (ini_get('magic_quotes_runtime')) {
-                               $data = stripslashes($data);
-                       }
-                       //return unserialize($data);
-                       return $data;
-               }
-               else 
-               {
-                       return NULL;
-               }
-       }
-
-       function set($name, $value)
-       {
-               //dba_replace($name, serialize($value), $this->db);
-               dba_replace($name, $value, $this->db);
-               return $value;
-       }
-
-       function exists($name)
-       {
-               return dba_exists($name, $this->db);
-       }
-
-       function del($name)
-       {
-               return dba_delete($name, $this->db);
-       }
-}
+if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
 
 try {
        if ($argc > 2) {
http://cvs.php.net/diff.php/php-src/ext/spl/examples/dba_dump.php?r1=1.6&r2=1.7&ty=u
Index: php-src/ext/spl/examples/dba_dump.php
diff -u php-src/ext/spl/examples/dba_dump.php:1.6 
php-src/ext/spl/examples/dba_dump.php:1.7
--- php-src/ext/spl/examples/dba_dump.php:1.6   Thu May  6 18:55:25 2004
+++ php-src/ext/spl/examples/dba_dump.php       Sat May  8 08:24:15 2004
@@ -9,7 +9,7 @@
  *
  * Note: configure with --enable-dba 
  *
- * (c) Marcus Boerger, 2003
+ * (c) Marcus Boerger, 2003 - 2004
  */
 
 if ($argc < 3) {
@@ -24,13 +24,13 @@
        exit(1);
 }
 
-require_once("dba_reader.inc");
-require_once("KeyFilter.inc");
+if (!class_exists("DbaReader")) require_once("dbareader.inc");
+if (!class_exists("KeyFilter")) require_once("keyfilter.inc");
 
 $db = new DbaReader($argv[1], $argv[2]);
 
 if ($argc>3) {
-       $db = new keyFilter($db, $argv[3]);
+       $db = new KeyFilter($db, $argv[3]);
 }
 
 foreach($db as $key => $val) {
http://cvs.php.net/diff.php/php-src/ext/spl/examples/directoryfilterdots.inc?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/directoryfilterdots.inc
diff -u php-src/ext/spl/examples/directoryfilterdots.inc:1.1 
php-src/ext/spl/examples/directoryfilterdots.inc:1.2
--- php-src/ext/spl/examples/directoryfilterdots.inc:1.1        Sun Nov  9 09:05:36 
2003
+++ php-src/ext/spl/examples/directoryfilterdots.inc    Sat May  8 08:24:15 2004
@@ -1,24 +1,48 @@
 <?php
 
+/** \ingroup Examples
+ * @brief   A filtered DirectoryIterator
+ * @author  Marcus Boerger
+ * @version 1.0
+ *
+ * This Iteraotr takes a pathname from which it creates a DirectoryIterator
+ * and makes it recursive. Further more it filters the entries '.' and '..'.
+ */
 class DirectoryFilterDots extends FilterIterator implements RecursiveIterator
 {
-       function __construct($path) {
+       /** Construct from a path.
+        * @param $path directory to iterate
+        */
+       function __construct($path)
+       {
                parent::__construct(new DirectoryIterator($path));
        }
-       
-       function accept() {
+
+       /** @return whether the current entry is neither '.' nor '..'
+        */     
+       function accept()
+       {
                return !$this->it->isDot();
        }
        
-       function hasChildren() {
+       /** @return whether the current entry is a directory
+        */
+       function hasChildren()
+       {
                return $this->it->hasChildren();
        }
 
-       function getChildren() {
+       /** @return the current subdirectory as a new DirectoryFilterDots instance.
+        */
+       function getChildren()
+       {
                return new DirectoryFilterDots($this->it->getPathname());
        }
        
-       function key() {
+       /** @return the current entries path name
+        */
+       function key()
+       {
                return $this->it->getPathname();
        }
 }
http://cvs.php.net/diff.php/php-src/ext/spl/examples/directorytree.inc?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/directorytree.inc
diff -u php-src/ext/spl/examples/directorytree.inc:1.1 
php-src/ext/spl/examples/directorytree.inc:1.2
--- php-src/ext/spl/examples/directorytree.inc:1.1      Sun Nov  9 09:05:36 2003
+++ php-src/ext/spl/examples/directorytree.inc  Sat May  8 08:24:15 2004
@@ -1,7 +1,15 @@
 <?php
 
+/** \ingroup Examples
+ * @brief   A directory iterator that does not show '.' and '..'.
+ * @author  Marcus Boerger
+ * @version 1.0
+ */
 class DirectoryTree extends RecursiveIteratorIterator
 {
+       /** Construct from a path.
+        * @param $path directory to iterate
+        */
        function __construct($path) {
                parent::__construct(new DirectoryFilterDots($path));
        }
http://cvs.php.net/diff.php/php-src/ext/spl/examples/directorytreeiterator.inc?r1=1.10&r2=1.11&ty=u
Index: php-src/ext/spl/examples/directorytreeiterator.inc
diff -u php-src/ext/spl/examples/directorytreeiterator.inc:1.10 
php-src/ext/spl/examples/directorytreeiterator.inc:1.11
--- php-src/ext/spl/examples/directorytreeiterator.inc:1.10     Tue Mar 16 05:16:52 
2004
+++ php-src/ext/spl/examples/directorytreeiterator.inc  Sat May  8 08:24:15 2004
@@ -1,12 +1,22 @@
 <?php
 
+/** \ingroup Examples
+ * @brief   DirectoryIterator to generate ASCII graphic directory trees
+ * @author  Marcus Boerger
+ * @version 1.0
+ */
 class DirectoryTreeIterator extends RecursiveIteratorIterator
 {
+       /** Construct from a path.
+        * @param $path directory to iterate
+        */
        function __construct($path)
        {
                parent::__construct(new CachingRecursiveIterator(new 
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD), 1);
        }
-       
+
+       /** @return the current element prefixed with ASCII graphics
+        */     
        function current()
        {
                $tree = '';
@@ -16,7 +26,9 @@
                return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') 
                       . $this->getSubIterator($l)->__toString();
        }
-       
+
+       /** Aggregates the inner iterator
+        */     
        function __call($func, $params)
        {
                return call_user_func_array(array($this->getSubIterator(), $func), 
$params);
http://cvs.php.net/diff.php/php-src/ext/spl/examples/emptyiterator.inc?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/emptyiterator.inc
diff -u php-src/ext/spl/examples/emptyiterator.inc:1.1 
php-src/ext/spl/examples/emptyiterator.inc:1.2
--- php-src/ext/spl/examples/emptyiterator.inc:1.1      Tue Apr 27 14:15:00 2004
+++ php-src/ext/spl/examples/emptyiterator.inc  Sat May  8 08:24:15 2004
@@ -1,6 +1,6 @@
 <?php
 
-/**
+/** \ingroup Examples
  * @brief   An empty Iterator
  * @author  Marcus Boerger
  * @version 1.0
@@ -8,26 +8,42 @@
  */
 class EmptyIterator implements Iterator
 {
+       /** No operation.
+        * @return void
+        */
        function rewind()
        {
                // nothing to do
        }
 
+       /** @return \c false
+        */
        function valid()
        {
                return false;
        }
 
+       /** This function must not be called. It throws an exception upon access.
+        * @throw Exception
+        * @return void
+        */
        function current()
        {
                throw new Exception('Accessing the value of an EmptyIterator');
        }
 
+       /** This function must not be called. It throws an exception upon access.
+        * @throw Exception
+        * @return void
+        */
        function key()
        {
                throw new Exception('Accessing the key of an EmptyIterator');
        }
 
+       /** No operation.
+        * @return void
+        */
        function next()
        {
                // nothing to do
http://cvs.php.net/diff.php/php-src/ext/spl/examples/findfile.inc?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/spl/examples/findfile.inc
diff -u php-src/ext/spl/examples/findfile.inc:1.3 
php-src/ext/spl/examples/findfile.inc:1.4
--- php-src/ext/spl/examples/findfile.inc:1.3   Wed Apr 28 15:58:47 2004
+++ php-src/ext/spl/examples/findfile.inc       Sat May  8 08:24:15 2004
@@ -1,15 +1,26 @@
 <?php
 
+if (!class_exists("FindFile")) require_once("findfile.inc");
+if (!class_exists("AppendIterator")) require_once("appenditerator.inc");
+
 /**
  * @brief   Base class to find files
  * @author  Marcus Boerger
- * @version 1.0
+ * @version 1.1
  *
  */
 class FindFile extends FilterIterator
 {
-       protected $file;
+       /** @internal filename to find */
+       private $file;
 
+       /** Construct from path and filename
+        *
+        * @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 $file the name of the files to search fro
+        */
        function __construct($path, $file)
        {
                $this->file = $file;
@@ -25,10 +36,21 @@
                }
        }
 
+       /** @return whether the current file matches the given filename
+        */
        function accept()
        {
                return !strcmp($this->current(), $this->file);
        }
+
+       /** @return the filename to search for.
+        * @note This may be overloaded and contain a regular expression for an
+        *       extended class that uses regular expressions to search.
+        */
+       function getSearch()
+       {
+               return $this->file;
+       }
 }
 
 ?>
\ No newline at end of file
http://cvs.php.net/diff.php/php-src/ext/spl/examples/findregex.php?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/findregex.php
diff -u php-src/ext/spl/examples/findregex.php:1.1 
php-src/ext/spl/examples/findregex.php:1.2
--- php-src/ext/spl/examples/findregex.php:1.1  Sun Jan 25 08:03:24 2004
+++ php-src/ext/spl/examples/findregex.php      Sat May  8 08:24:15 2004
@@ -24,15 +24,10 @@
        exit(1);
 }
 
-class RegexFindFile extends FindFile
-{
-       function accept()
-       {
-               return preg_match($this->file, $this->current());
-       }
-}
+if (!class_exists("RegexFindFile")) require_once("regexfindfile.inc");
 
-foreach(new RegexFindFile($argv[1], $argv[2]) as $file) {
+foreach(new RegexFindFile($argv[1], $argv[2]) as $file)
+{
        echo $file->getPathname()."\n";
 }
 
http://cvs.php.net/diff.php/php-src/ext/spl/examples/infiniteiterator.inc?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/infiniteiterator.inc
diff -u php-src/ext/spl/examples/infiniteiterator.inc:1.1 
php-src/ext/spl/examples/infiniteiterator.inc:1.2
--- php-src/ext/spl/examples/infiniteiterator.inc:1.1   Tue Apr 27 14:15:00 2004
+++ php-src/ext/spl/examples/infiniteiterator.inc       Sat May  8 08:24:15 2004
@@ -1,6 +1,6 @@
 <?php
 
-/**
+/** \ingroup Examples
  * @brief   An infinite Iterator
  * @author  Marcus Boerger
  * @version 1.0
@@ -22,38 +22,57 @@
  */
 class InfiniteIterator implements Iterator
 {
+       /** @internal 
+        * The inner Iterator. */
        private $it;
 
+       /** Construct from another Iterator.
+        * @param $it the inner Iterator.
+        */
        function __construct(Iterator $it)
        {
                $this->it = $it;
        }
 
+       /** @return the inner iterator
+        */
        function getInnerIterator()
        {
                return $this->it;
        }
 
+       /** Rewind the inner iterator.
+        * @return void
+        */
        function rewind()
        {
                $this->it->rewind();
        }
 
+       /** @return whether the current element is valid
+        */
        function valid()
        {
                return $this->it->valid();
        }
 
+       /** @return the current value
+        */
        function current()
        {
                return $this->it->current();
        }
 
+       /** @return the current key
+        */
        function key()
        {
                return $this->it->key();
        }
 
+       /** Move the inner Iterator forward to its next element or rewind it.
+        * @return void
+        */
        function next()
        {
                $this->it->next();
@@ -62,6 +81,13 @@
                        $this->it->rewind();
                }
        }
+
+       /** Aggregates the inner iterator
+        */     
+       function __call($func, $params)
+       {
+               return call_user_func_array(array($this->getSubIterator(), $func), 
$params);
+       }
 }
 
 ?>
\ No newline at end of file
http://cvs.php.net/diff.php/php-src/ext/spl/examples/ini_groups.php?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/spl/examples/ini_groups.php
diff -u php-src/ext/spl/examples/ini_groups.php:1.3 
php-src/ext/spl/examples/ini_groups.php:1.4
--- php-src/ext/spl/examples/ini_groups.php:1.3 Thu May  6 18:55:25 2004
+++ php-src/ext/spl/examples/ini_groups.php     Sat May  8 08:24:15 2004
@@ -24,8 +24,8 @@
        exit(1);
 }
 
-require_once("dba_reader.inc");
-require_once("IniGroups.inc");
+if (!class_exists("KeyFilter")) require_once("keyfilter.inc");
+if (!class_exists("IniGroups")) require_once("inigroups.inc");
 
 $it = new IniGroups($argv[1]);
 if ($argc>2) {
http://cvs.php.net/diff.php/php-src/ext/spl/examples/searchiterator.inc?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/spl/examples/searchiterator.inc
diff -u php-src/ext/spl/examples/searchiterator.inc:1.3 
php-src/ext/spl/examples/searchiterator.inc:1.4
--- php-src/ext/spl/examples/searchiterator.inc:1.3     Mon Mar  8 12:33:30 2004
+++ php-src/ext/spl/examples/searchiterator.inc Sat May  8 08:24:15 2004
@@ -1,21 +1,49 @@
 <?php
 
+/** @ingroup Examples
+ * @brief Iterator to search for a specific element
+ * @author  Marcus Boerger
+ * @version 1.0
+ *
+ * This extended FilterIterator stops after finding the first acceptable
+ * value.
+ */
 abstract class SearchIterator extends FilterIterator
 {
+       /** @internal whether an entry was found already */
        private $done = false;
 
-       function rewind() {
+       /** Rewind and reset so that it once again searches.
+        * @return void
+        */
+       function rewind()
+       {
                parent::rewind();
                $this->done = false;
        }
 
-       function valid() {
+       /** @return whether the current element is valid
+        * which can only happen once per iteration.
+        */
+       function valid()
+       {
                return !$this->done && parent::valid();
        }
        
-       function next() {
+       /** Do not move forward but instead mark as finished.
+        * @return void
+        */
+       function next()
+       {
                $this->done = true;
        }
+
+       /** Aggregates the inner iterator
+        */     
+       function __call($func, $params)
+       {
+               return call_user_func_array(array($this->getSubIterator(), $func), 
$params);
+       }
 }
 
 ?>
\ No newline at end of file
http://cvs.php.net/diff.php/php-src/ext/spl/examples/tree.php?r1=1.7&r2=1.8&ty=u
Index: php-src/ext/spl/examples/tree.php
diff -u php-src/ext/spl/examples/tree.php:1.7 php-src/ext/spl/examples/tree.php:1.8
--- php-src/ext/spl/examples/tree.php:1.7       Sat Dec 13 09:40:06 2003
+++ php-src/ext/spl/examples/tree.php   Sat May  8 08:24:15 2004
@@ -6,7 +6,7 @@
  *
  * Simply specify the path to tree with parameter <path>.
  *
- * (c) Marcus Boerger, 2003
+ * (c) Marcus Boerger, 2003 - 2004
  */
 
 // The following line only operates on classes which are converted to c already.
@@ -26,8 +26,11 @@
        exit(1);
 }
 
+if (!class_exists("DirectoryTreeIterator")) require_once("directorytreeiterator.inc");
+
 echo $argv[1]."\n";
-foreach(new DirectoryGraphIterator($argv[1]) as $file) {
+foreach(new DirectoryTreeIterator($argv[1]) as $file)
+{
        echo $file . "\n";
 }
 

http://cvs.php.net/co.php/php-src/ext/spl/internal/cachingiterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/cachingiterator.inc
+++ php-src/ext/spl/internal/cachingiterator.inc
<?php

define('CIT_CALL_TOSTRING', 1);
define('CIT_CATCH_GET_CHILD', 2);

class CachingIterator
{
        protected $it;
        protected $current;
        protected $key;
        protected $valid;
        protected $strValue;

        function __construct(Iterator $it, $flags = CIT_CALL_TOSTRING)
        {
                $this->it = $it;
                $this->flags = $flags & (CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD);
                $this->next();
        }

        function rewind()
        {
                $this->it->rewind();
                $this->next();
        }
        
        function next()
        {
                if ($this->valid = $this->it->valid()) {
                        $this->current = $this->it->current();
                        $this->key = $this->it->key();
                        if ($this->flags & CIT_CALL_TOSTRING) {
                                if (is_object($this->current)) {
                                        $this->strValue = $this->current->__toString();
                                } else {
                                        $this->strValue = (string)$this->current;
                                }
                        }
                } else {
                        $this->current = NULL;
                        $this->key = NULL;
                        $this->strValue = NULL;
                }
                $this->it->next();
        }
        
        function valid()
        {
                return $this->valid;
        }

        function hasNext()
        {
                return $this->it->valid();
        }
        
        function current()
        {
                return $this->current;
        }

        function key()
        {
                return $this->key;
        }

        function __call($func, $params)
        {
                return call_user_func_array(array($this->it, $func), $params);
        }
        
        function __toString()
        {
                if (!$this->flags & CIT_CALL_TOSTRING) {
                        throw new exception('CachingIterator does not fetch string 
value (see CachingIterator::__construct)');
                }
                return $this->strValue;
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/cachingrecursiveiterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/cachingrecursiveiterator.inc
+++ php-src/ext/spl/internal/cachingrecursiveiterator.inc
<?php

class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator
{
        protected $hasChildren;
        protected $getChildren;

        function __construct(RecursiveIterator $it, $flags = CIT_CALL_TOSTRING)
        {
                parent::__construct($it, $flags);
        }
        
        function rewind();
        {
           $this->hasChildren = false;
           $this->getChildren = NULL;
           parent::rewind();
        }

        function next()
        {
                if ($this->hasChildren = $this->it->hasChildren()) {
                        try {
                                //$this->getChildren = new 
CachingRecursiveIterator($this->it->getChildren(), $this->flags);
                                // workaround memleaks...
                                $child = $this->it->getChildren();
                                $this->getChildren = new 
CachingRecursiveIterator($child, $this->flags);
                        }
                        catch(Exception $e) {
                                if (!$this->flags & CIT_CATCH_GET_CHILD) {
                                        throw $e;
                                }
                                $this->hasChildren = false;
                                $this->getChildren = NULL;
                        }
                } else {
                        $this->getChildren = NULL;
                }
                parent::next();
        }

        function hasChildren()
        {
                return $this->hasChildren;
        }

        function getChildren()
        {
                return $this->getChildren;
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/filteriterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/filteriterator.inc
+++ php-src/ext/spl/internal/filteriterator.inc
<?php

/**
 * @brief   Regular expression filter for string iterators
 * @author  Marcus Boerger
 * @version 1.0
 *
 * Instances of this class act as a filter around iterators. In other words 
 * you can put an iterator into the constructor and the instance will only 
 * return selected (accepted) elements.
 */
abstract class FilterIterator implements Iterator
{
        protected $it;

        /**
         * Constructs a filter around an iterator whose elemnts are strings.
         * If the given iterator is of type spl_sequence then its rewind()
         * method is called.
         *
         * @param it     Object that implements at least spl_forward
         */
        function __construct(Iterator $it) {
                $this->it = $it;
        }

        /**
         * Rewind the inner iterator.
         */
        function rewind() {     
                $this->it->rewind();
                $this->fetch();
        }

        /**
         * Accept function to decide whether an element of the inner iterator
         * should be accessible through the Filteriterator.
         *
         * @return whether or not to expose the current element of the inner
         *         iterator.
         */
        abstract function accept();

        /**
         * Fetch next element and store it.
         *
         * @return void
         */
        protected function fetch() {
                while ($this->it->valid()) {
                        if ($this->accept()) {
                                return;
                        }
                        $this->it->next();
                };
        }

        /**
         * Move to next element
         *
         * @return void
         */
        function next() {
                $this->it->next();
                $this->fetch();
        }
        
        /**
         * @return Whether more elements are available
         */
        function valid() {
                return $this->it->valid();
        }
        
        /**
         * @return The current key
         */
        function key() {
                return $this->it->key();
        }
        
        /**
         * @return The current value
         */
        function current() {
                return $this->it->current();
        }
        
        /**
         * hidden __clone
         */
        protected function __clone() {
                // disallow clone 
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/limititerator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/limititerator.inc
+++ php-src/ext/spl/internal/limititerator.inc
<?php

class LimitIterator implements Iterator
{
        protected $it;
        protected $offset;
        protected $count;
        private $pos;

        // count === NULL means all
        function __construct(Iterator $it, $offset = 0, $count = -1)
        {
                if ($offset < 0) {
                        throw new exception('Parameter offset must be > 0');
                }
                if ($count < 0 && $count != -1) {
                        throw new exception('Parameter count must either be -1 or a 
value greater than or equal to 0');
                }
                $this->it     = $it;
                $this->offset = $offset;
                $this->count  = $count;
                $this->pos    = 0;
        }
        
        function seek($position) {
                if ($position < $this->offset) {
                        throw new exception('Cannot seek to '.$position.' which is 
below offset '.$this->offset);
                }
                if ($position > $this->offset + $this->count && $this->count != -1) {
                        throw new exception('Cannot seek to '.$position.' which is 
behind offset '.$this->offset.' plus count '.$this->count);
                }
                if ($this->it instanceof SeekableIterator) {
                        $this->it->seek($position);
                        $this->pos = $position;
                } else {
                        while($this->pos < $position && $this->it->valid()) {
                                $this->next();
                        }
                }
        }

        function rewind()
        {
                $this->it->rewind();
                $this->pos = 0;
                $this->seek($this->offset);
        }
        
        function valid() {
                return ($this->count == -1 || $this->pos < $this->offset + 
$this->count)
                         && $this->it->valid();
        }
        
        function key() {
                return $this->it->key();
        }

        function current() {
                return $this->it->current();
        }

        function next() {
                $this->it->next();
                $this->pos++;
        }

        function getPosition() {
                return $this->pos;
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/parentiterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/parentiterator.inc
+++ php-src/ext/spl/internal/parentiterator.inc
<?php

class ParentIterator extends FilterIterator implements RecursiveIterator
{
        function __construct(RecursiveIterator $it)
        {
                parent::__construct($it);
        }
        function accept()
        {
                return $this->it->hasChildren();
        }

        function hasChildren()
        {
                return $this->it->hasChildren();
        }

        function getChildren()
        {
                return new ParentIterator($this->it->getChildren());
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/recursiveiterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/recursiveiterator.inc
+++ php-src/ext/spl/internal/recursiveiterator.inc
<?php

interface RecursiveIterator implements Iterator
{
        function hasChildren();
        function getChildren();
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/recursiveiteratoriterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/recursiveiteratoriterator.inc
+++ php-src/ext/spl/internal/recursiveiteratoriterator.inc
<?php

/**
 * @brief   Iterates through recursive iterators
 * @author  Marcus Boerger
 * @version 1.0
 *
 */
class RecursiveIteratorIterator implements Iterator
{
        protected $ait = array();
        protected $count = 0;

        function __construct(RecursiveIterator $it)
        {
                $this->ait[0] = $it;
        }


        function rewind()
        {
                while ($this->count) {
                        unset($this->ait[$this->count--]);
                }
                $this->ait[0]->rewind();
                $this->ait[0]->recursed = false;
        }
        
        function valid()
        {
                $count = $this->count;
                while ($count) {
                        $it = $this->ait[$count];
                        if ($it->valid()) {
                                return true;
                        }
                        $count--;
                }
                return false;
        }
        
        function key()
        {
                $it = $this->ait[$this->count];
                return $it->key();
        }
        
        function current()
        {
                $it = $this->ait[$this->count];
                return $it->current();
        }
        
        function next()
        {
                while ($this->count) {
                        $it = $this->ait[$this->count];
                        if ($it->valid()) {
                                if (!$it->recursed && $it->hasChildren()) {
                                        $it->recursed = true;
                                        $sub = $it->getChildren();
                                        $sub->recursed = false;
                                        $sub->rewind();
                                        if ($sub->valid()) {
                                                $this->ait[++$this->count] = $sub;
                                                if (!$sub instanceof 
RecursiveIterator) {
                                                        throw new 
Exception(get_class($sub).'::getChildren() must return an object that implements 
RecursiveIterator');
                                                } 
                                                return;
                                        }
                                        unset($sub);
                                }
                                $it->next();
                                $it->recursed = false;
                                if ($it->valid()) {
                                        return;
                                }
                                $it->recursed = false;
                        }
                        if ($this->count) {
                                unset($this->ait[$this->count--]);
                                $it = $this->ait[$this->count];
                        }
                }
        }
        
        function getSubIterator($level = NULL)
        {
                if (is_null($level)) {
                        $level = $this->count;
                }
                return @$this->ait[$level];
        }

        function getDepth()
        {
                return $this->level;
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/internal/seekableiterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/seekableiterator.inc
+++ php-src/ext/spl/internal/seekableiterator.inc
<?php

/** \brief seekable iterator
 *
 * Turns a normal iterator ino a seekable iterator. When there is a way
 * to seek on an iterator LimitIterator can use this to efficiently rewind
 * to offset.
 */
interface SeekableIterator implements Iterator
{
        /** Seek to an absolute position
         *
         * \param $index position to seek to
         * \return void
         *
         * \note The method should throw an exception if it is not possible to
         *       seek to the given position.
         */
        function seek($index);
/*              $this->rewind();
                $position = 0;
                while($position < $index && $this->valid()) {
                        $this->next();
                        $position++;
                }
        }*/
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/examples/dbaarray.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/dbaarray.inc
+++ php-src/ext/spl/examples/dbaarray.inc
<?php

if (!class_exists("DbaReader")) require_once("dbareader.inc");

/** \ingroup Examples
 * @brief   This implements a DBA Array
 * @author  Marcus Boerger
 * @version 1.0
 */
class DbaArray extends DbaReader implements ArrayAccess
{

        /**
         * Open database $file with $handler in read only mode.
         *
         * @param file    Database file to open.
         * @param handler Handler to use for database access.
         */
        function __construct($file, $handler)
        {
                $this->db = dba_popen($file, "c", $handler);
                if (!$this->db) {
                        throw new exception("Databse could not be opened");
                }
        }

        /**
         * Close database.
         */
        function __destruct()
        {
                parent::__destruct();
        }

        /**
         * Read an entry.
         *
         * @param $name key to read from
         * @return value associated with $name
         */
        function offsetGet($name)
        {
                $data = dba_fetch($name, $this->db); 
                if($data) {
                        if (ini_get('magic_quotes_runtime')) {
                                $data = stripslashes($data);
                        }
                        //return unserialize($data);
                        return $data;
                }
                else 
                {
                        return NULL;
                }
        }

        /**
         * Set an entry.
         *
         * @param $name key to write to
         * @param $value value to write
         */
        function offsetSet($name, $value)
        {
                //dba_replace($name, serialize($value), $this->db);
                dba_replace($name, $value, $this->db);
                return $value;
        }

        /**
         * @return whether key $name exists.
         */
        function offsetExists($name)
        {
                return dba_exists($name, $this->db);
        }

        /**
         * Delete a key/value pair.
         *
         * @param $name key to delete.
         */
        function offsetUnset($name)
        {
                return dba_delete($name, $this->db);
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/examples/dbareader.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/dbareader.inc
+++ php-src/ext/spl/examples/dbareader.inc
<?php

/** \ingroup Examples
 * @brief   This implements a DBA Iterator.
 * @author  Marcus Boerger
 * @version 1.0
 */
class DbaReader implements Iterator
{

        protected $db = NULL;
        private $key = false;
        private $val = false;

        /**
         * Open database $file with $handler in read only mode.
         *
         * @param file    Database file to open.
         * @param handler Handler to use for database access.
         */
        function __construct($file, $handler) {
                $this->db = dba_open($file, 'r', $handler);
        }
        
        /**
         * Close database.
         */
        function __destruct() {
                if ($this->db) {
                        dba_close($this->db);
                }
        }

        /**
         * Rewind to first element.
         */
        function rewind() {
                if ($this->db) {
                        $this->key = dba_firstkey($this->db);
                }
        }

        /**
         * @return Current data.
         */
        function current() {
                return $this->val;
        }

        /**
         * Move to next element.
         *
         * @return void
         */
        function next() {
                if ($this->db) {
                        $this->key = dba_nextkey($this->db);
                        if ($this->key !== false) {
                                $this->val = dba_fetch($this->key, $this->db);
                        }
                }
        }

        /**
         * @return Whether more elements are available.
         */
        function valid() {
                if ($this->db && $this->key !== false) {
                        return true;
                } else {
                        return false;
                }
        }

        /**
         * @return Current key.
         */
        function key() {
                return $this->key;
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/examples/inigroups.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/inigroups.inc
+++ php-src/ext/spl/examples/inigroups.inc
<?php

if (!class_exists("KeyFilter")) require_once("keyfilter.inc");
if (!class_exists("DbaReader")) require_once("dbareader.inc");

/** \ingroup Examples
 * @brief   Class to iterate all groups within an ini file.
 * @author  Marcus Boerger
 * @version 1.1
 *
 * Using this class you can iterator over all groups of a ini file.
 * 
 * This class uses a 'is-a' relation to KeyFilter in contrast to a 'has-a'
 * relation. Doing so both current() and key() methods must be overwritten. 
 * If it would use a 'has-a' relation there would be much more to type...
 * but for puritists that would allow correctness in so far as then no 
 * key() would be needed.
 */
class IniGroups extends KeyFilter
{
        /**
         * Construct an ini file group iterator from a filename.
         *
         * @param file Ini file to open.
         */
        function __construct($file) {
                parent::__construct(new DbaReader($file, 'inifile'), '^\[.*\]$');
        }

        /**
         * @return The current group.
         */
        function current() {
                return substr(parent::key(),1,-1);
        }

        /**
         * @return The current group.
         */
        function key() {
                return substr(parent::key(),1,-1);
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/examples/keyfilter.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/keyfilter.inc
+++ php-src/ext/spl/examples/keyfilter.inc
<?php

/** \ingroup Examples
 * @brief   Regular expression filter for string iterators
 * @author  Marcus Boerger
 * @version 1.1
 *
 * Instances of this class act as a filter around iterators whose elements
 * are strings. In other words you can put an iterator into the constructor
 * and the instance will only return elements which match the given regular 
 * expression.
 */
class KeyFilter extends FilterIterator
{
        /** @internal regular exoression used as filter */
        private $regex;

        /**
         * Constructs a filter around an iterator whose elemnts are strings.
         * If the given iterator is of type spl_sequence then its rewind()
         * method is called.
         *
         * @param it     Object that implements at least spl_forward
         * @param regex  Regular expression used as a filter.
         */
        function __construct(Iterator $it, $regex)
        {
                parent::__construct($it);
                $this->regex = $regex;
        }

        /** \return whether the current key mathes the regular expression 
         */
        function accept()
        {
                return ereg($this->regex, $this->getInnerIterator()->key());
        }
        
        /** @return regular expression used as filter
         */
        function getRegex()
        {
                return $this->regex;
        }

        /**
         * hidden __clone
         */
        protected function __clone()
        {
                // disallow clone 
        }
}

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

Reply via email to