Skip to content

Commit

Permalink
Add a method to forget all queued event handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 2, 2014
1 parent 8615680 commit 2e3f553
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,17 @@ public function forget($event)
unset($this->listeners[$event], $this->sorted[$event]);
}

/**
* Forget all of the queued listeners.
*
* @return void
*/
public function forgetQueued()
{
foreach ($this->listeners as $key => $value)
{
if (ends_with($key, '_queue')) $this->forget($key);
}
}

}
16 changes: 16 additions & 0 deletions tests/Events/EventsDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public function testQueuedEventsAreFired()
}


public function testQueuedEventsCanBeForgotten()
{
$_SERVER['__event.test'] = 'unset';
$d = new Dispatcher;
$d->queue('update', array('name' => 'taylor'));
$d->listen('update', function($name)
{
$_SERVER['__event.test'] = $name;
});

$d->forgetQueued();
$d->flush('update');
$this->assertEquals('unset', $_SERVER['__event.test']);
}


public function testWildcardListeners()
{
unset($_SERVER['__event.test']);
Expand Down

0 comments on commit 2e3f553

Please sign in to comment.