Commit c4975cc4 authored by Jérôme Tamarelle's avatar Jérôme Tamarelle

Create Application::on() method to add an event listener

parent 81bafcc6
......@@ -270,6 +270,19 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return $this['controllers']->delete($pattern, $to);
}
/**
* Adds an event listener that listens on the specified events.
*
* @param string $eventName The event to listen on
* @param callable $listener The listener
* @param integer $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public function on($eventName, $callback, $priority = 0)
{
return $this['dispatcher']->addListener($eventName, $callback, $priority);
}
/**
* Registers a before filter.
*
......
......@@ -106,6 +106,20 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foobar', $response->getContent());
}
public function testOn()
{
$app = new Application();
$app['pass'] = false;
$app->on('test', function(Event $e) use ($app) {
$app['pass'] = true;
});
$app['dispatcher']->dispatch('test');
$this->assertTrue($app['pass']);
}
public function testAbort()
{
$app = new Application();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment