- Fixed #ZETACOMP-39: ezcBaseOptions implements Iterator


git-svn-id: https://svn.apache.org/repos/asf/incubator/zetacomponents/trunk@1088209 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/Base/src/options.php b/Base/src/options.php
index 8cb6b7e..607479e 100644
--- a/Base/src/options.php
+++ b/Base/src/options.php
@@ -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 @@
     {
         $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
diff --git a/Base/tests/base_options_test.php b/Base/tests/base_options_test.php
index 946691b..eee7815 100644
--- a/Base/tests/base_options_test.php
+++ b/Base/tests/base_options_test.php
@@ -141,6 +141,22 @@
             $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
diff --git a/Base/tests/test_options.php b/Base/tests/test_options.php
index c86a017..f7b6c75 100644
--- a/Base/tests/test_options.php
+++ b/Base/tests/test_options.php
@@ -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 @@
         }
     }
 }
-?>
+?>
\ No newline at end of file