helly           Thu May  6 18:55:25 2004 EDT

  Added files:                 
    /php-src/ext/spl/examples   IniGroups.inc KeyFilter.inc 

  Removed files:               
    /php-src/ext/spl/examples   key_filter.inc 

  Modified files:              
    /php-src/ext/spl    spl.php 
    /php-src/ext/spl/examples   dba_dump.php ini_groups.php 
  Log:
  - Update examples
  
  
http://cvs.php.net/diff.php/php-src/ext/spl/spl.php?r1=1.22&r2=1.23&ty=u
Index: php-src/ext/spl/spl.php
diff -u php-src/ext/spl/spl.php:1.22 php-src/ext/spl/spl.php:1.23
--- php-src/ext/spl/spl.php:1.22        Thu May  6 17:46:40 2004
+++ php-src/ext/spl/spl.php     Thu May  6 18:55:25 2004
@@ -1,10 +1,36 @@
 <?php
 
-/** Standard PHP Library
+/** \mainpage SPL - Standard PHP Library
+ *
+ * SPL - Standard PHP Library
  *
  * (c) Marcus Boerger, 2003 - 2004
  */
 
+/** Interface to override array access of objects.
+ */
+interface ArrayAccess
+{
+       /** \param $offset to modify
+        * \param $value new value
+        */
+       function offsetSet($offset, $value);
+
+       /** \param $offset to retrieve
+        * \return value at given offset
+        */
+       function offsetGet($offset);
+
+       /** \param $offset to delete
+        */
+       function offsetUnset($offset);
+
+       /** \param $offset to check
+        *\return whether the offset exists.
+        */
+       function offsetExists($offset);
+}
+
 /** Abstract base interface that cannot be implemented alone. Instead it
  * must be implemented by either IteratorAggregate or Iterator. 
  *
@@ -343,7 +369,7 @@
 
 /** The recursive version of the CachingIterator.
  */
-class CachingRecursiveIterator extends CachingIterator implemnets RecursiveIterator
+class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator
 {
        /** Construct an instance form a RecursiveIterator.
         *
http://cvs.php.net/diff.php/php-src/ext/spl/examples/dba_dump.php?r1=1.5&r2=1.6&ty=u
Index: php-src/ext/spl/examples/dba_dump.php
diff -u php-src/ext/spl/examples/dba_dump.php:1.5 
php-src/ext/spl/examples/dba_dump.php:1.6
--- php-src/ext/spl/examples/dba_dump.php:1.5   Thu Dec  4 14:39:46 2003
+++ php-src/ext/spl/examples/dba_dump.php       Thu May  6 18:55:25 2004
@@ -25,7 +25,7 @@
 }
 
 require_once("dba_reader.inc");
-require_once("key_filter.inc");
+require_once("KeyFilter.inc");
 
 $db = new DbaReader($argv[1], $argv[2]);
 
http://cvs.php.net/diff.php/php-src/ext/spl/examples/ini_groups.php?r1=1.2&r2=1.3&ty=u
Index: php-src/ext/spl/examples/ini_groups.php
diff -u php-src/ext/spl/examples/ini_groups.php:1.2 
php-src/ext/spl/examples/ini_groups.php:1.3
--- php-src/ext/spl/examples/ini_groups.php:1.2 Thu Dec  4 14:39:46 2003
+++ php-src/ext/spl/examples/ini_groups.php     Thu May  6 18:55:25 2004
@@ -9,7 +9,7 @@
  *
  * Note: configure with --enable-dba 
  *
- * (c) Marcus Boerger, 2003
+ * (c) Marcus Boerger, 2003 - 2004
  */
 
 if ($argc < 2) {
@@ -25,50 +25,11 @@
 }
 
 require_once("dba_reader.inc");
-require_once("key_filter.inc");
+require_once("IniGroups.inc");
 
-/**
- * @brief   Class to iterate all groups within an ini file.
- * @author  Marcus Boerger
- * @version 1.0
- *
- * Using this class you can iterator over all groups of a ini file.
- * 
- * This class uses a 'is-a' relation to key_filter 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 ini_groups extends key_filter
-{
-       /**
-        * Construct an ini file group iterator from a filename.
-        *
-        * @param file Ini file to open.
-        */
-       function __construct($file) {
-               parent::__construct(new dba_reader($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);
-       }
-}
-
-$it = new ini_groups($argv[1]);
+$it = new IniGroups($argv[1]);
 if ($argc>2) {
-       $it = new key_filter($it, $argv[2]);
+       $it = new KeyFilter($it, $argv[2]);
 }
 
 foreach($it as $group) {

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

require_once("KeyFilter.inc");

/**
 * @brief   Class to iterate all groups within an ini file.
 * @author  Marcus Boerger
 * @version 1.0
 *
 * 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 dba_reader($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

/**
 * @brief   Regular expression filter for string iterators
 * @author  Marcus Boerger
 * @version 1.0
 *
 * 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 implements Iterator
{
        protected $it;
        protected $regex;
        protected $key;
        protected $curr;

        /**
         * 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) {
                $this->it = $it;
                $this->regex = $regex;
                $this->fetch();
        }

        /**
         * Rewind input iterator
         */
        function rewind() {
                $this->it->rewind();
        }
        
        /**
         * Destruct the iterator.
         */
        function __destruct() {
                unset($this->it);
        }

        /**
         * Fetch next element and store it.
         *
         * @return void
         */
        protected function fetch() {
                $this->key = false;
                $this->curr = false;
                while ($this->it->valid()) {
                        $key = $this->it->key();
                        if (ereg($this->regex, $key)) {
                                $this->key = $key;
                                $this->curr = $this->it->current();
                                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->key !== false;
        }
        
        /**
         * @return The current key
         */
        function key() {
                return $this->key;
        }
        
        /**
         * @return The current value
         */
        function current() {
                return $this->curr;
        }
        
        /**
         * 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