Skip to content

Commit

Permalink
[EventDispatcher] Adding IteratorAggregate to GenericEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Aug 15, 2012
1 parent 50df1a7 commit 0ad00f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Symfony/Component/EventDispatcher/GenericEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Drak <[email protected]>
*/
class GenericEvent extends Event implements \ArrayAccess
class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
{
/**
* Observer pattern subject.
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0ad00f8

Please sign in to comment.