8000 [EventDispatcher] Adding IteratorAggregate to GenericEvent by mtdowling · Pull Request #5268 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[EventDispatcher] Adding IteratorAggregate to GenericEvent #5268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[EventDispatcher] Adding IteratorAggregate to GenericEvent
  • Loading branch information
mtdowling committed Aug 15, 2012
commit 0ad00f8a564a48ca8f865a9c5cdb13d0661051ad
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 <drak@zikula.org>
*/
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