incubator-zeta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jero...@apache.org
Subject [zeta-commits] svn commit: r1088209 - in /incubator/zetacomponents/trunk/Base: src/options.php tests/base_options_test.php tests/test_options.php
Date Sun, 03 Apr 2011 05:22:55 GMT
Author: jeromer
Date: Sun Apr  3 05:22:55 2011
New Revision: 1088209

URL: http://svn.apache.org/viewvc?rev=1088209&view=rev
Log:
- Fixed #ZETACOMP-39: ezcBaseOptions implements Iterator

Modified:
    incubator/zetacomponents/trunk/Base/src/options.php
    incubator/zetacomponents/trunk/Base/tests/base_options_test.php
    incubator/zetacomponents/trunk/Base/tests/test_options.php

Modified: incubator/zetacomponents/trunk/Base/src/options.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Base/src/options.php?rev=1088209&r1=1088208&r2=1088209&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Base/src/options.php (original)
+++ incubator/zetacomponents/trunk/Base/src/options.php Sun Apr  3 05:22:55 2011
@@ -30,7 +30,7 @@
  * @package Base
  * @version //autogentag//
  */
-abstract class ezcBaseOptions implements ArrayAccess
+abstract class ezcBaseOptions implements ArrayAccess, Iterator
 {
     /**
      * Container to hold the properties
@@ -186,5 +186,63 @@ abstract class ezcBaseOptions implements
     {
         $this->__set( $propertyName, null );
     }
+
+    /**
+     * Return the current element.
+     *
+     * @return void
+     */
+    public function current()
+    {
+        return current( $this->properties );
+    }
+
+    /**
+     * Return the key of the current element.
+     *
+     * @return void
+     */
+    public function key()
+    {
+        return key( $this->properties );
+    }
+
+    /**
+     * Move forward to next element.
+     *
+     * @return void
+     */
+    public function next()
+    {
+        return next( $this->properties );
+    }
+
+    /**
+     * Rewind the Iterator to the first element.
+     *
+     * @return void
+     */
+    public function rewind()
+    {
+        reset( $this->properties );
+    }
+
+    /**
+     * Check if there is a current element after calls to {@link rewind()} or
+     * {@link next()}.
+     *
+     * @return void
+     */
+    public function valid()
+    {
+        $key = key( $this->properties );
+
+        if( $key !== null && $key !== false)
+        {
+            return true;
+        }
+
+        return false;
+    }
 }
-?>
+?>
\ No newline at end of file

Modified: incubator/zetacomponents/trunk/Base/tests/base_options_test.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Base/tests/base_options_test.php?rev=1088209&r1=1088208&r2=1088209&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Base/tests/base_options_test.php (original)
+++ incubator/zetacomponents/trunk/Base/tests/base_options_test.php Sun Apr  3 05:22:55 2011
@@ -141,6 +141,22 @@ class ezcBaseOptionsTest extends ezcTest
             $this->assertEquals( "The value 'wrong value' that you were trying to assign
to setting 'preload' is invalid. Allowed values are: bool.", $e->getMessage() );
         }
     }
+
+    public function testIterator()
+    {
+        $options = new ezcBaseTestOptions();
+
+        $expectedArray = array( "foo" => "bar", "baz" => "blah" );
+
+        $resultArray = array();
+
+        foreach( $options as $key => $option )
+        {
+            $resultArray[$key] = $option;
+        }
+
+        $this->assertEquals( $expectedArray, $resultArray );
+    }
 }
 
-?>
+?>
\ No newline at end of file

Modified: incubator/zetacomponents/trunk/Base/tests/test_options.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Base/tests/test_options.php?rev=1088209&r1=1088208&r2=1088209&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Base/tests/test_options.php (original)
+++ incubator/zetacomponents/trunk/Base/tests/test_options.php Sun Apr  3 05:22:55 2011
@@ -1,7 +1,7 @@
 <?php
 class ezcBaseTestOptions extends ezcBaseOptions
 {
-    protected $properties = array( "foo" => "bar" );
+    protected $properties = array( "foo" => "bar", "baz" => "blah" );
 
     public function __set( $propertyName, $propertyValue )
     {
@@ -15,4 +15,4 @@ class ezcBaseTestOptions extends ezcBase
         }
     }
 }
-?>
+?>
\ No newline at end of file



Mime
View raw message