Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[EventDispatcher] Adding IteratorAggregate to GenericEvent

  • Loading branch information...
commit 76c76f62702b09e0f182ae618be0f1d79e2a711f 1 parent 451e0be
@mtdowling mtdowling authored
Showing with 20 additions and 1 deletion.
  1. +11 −1 GenericEvent.php
  2. +9 −0 Tests/GenericEventTest.php
View
12 GenericEvent.php
@@ -18,7 +18,7 @@
*
* @author Drak <drak@zikula.org>
*/
-class GenericEvent extends Event implements \ArrayAccess
+class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
{
/**
* Observer pattern subject.
@@ -177,4 +177,14 @@ public function offsetExists($key)
{
return $this->hasArgument($key);
}
+
+ /**
+ * IteratorAggregate for iterating over the object like an array
+ *
+ * @return \ArrayIterator
+ */
+ public function getIterator()
+ {
+ return new \ArrayIterator($this->arguments);
+ }
}
View
9 Tests/GenericEventTest.php
@@ -128,4 +128,13 @@ public function testGetSubject()
{
$this->assertSame($this->subject, $this->event->getSubject());
}
+
+ public function testHasIterator()
+ {
+ $data = array();
+ foreach ($this->event as $key => $value) {
+ $data[$key] = $value;
+ }
+ $this->assertEquals(array('name' => 'Event'), $data);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.