public function testFilter() { $listener = new Listener(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFoo')); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $e = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo'); $this->assertEquals('-*foo*-', $e->getReturnValue(), '->filter() filters a value'); $this->assertEquals($event, $e, '->filter() returns the event object'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $dispatcher->connect('foo', array($listener, 'filterFoo')); $e = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo'); $this->assertEquals('*-foo-*', $e->getReturnValue(), '->filter() filters a value'); }
$dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $e = $dispatcher->notifyUntil($event = new Event(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); // ->filter() $t->diag('->filter()'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFoo')); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $e = $dispatcher->filter($event = new Event(new stdClass(), 'foo'), 'foo'); $t->is($e->getReturnValue(), '-*foo*-', '->filter() filters a value'); $t->is($e, $event, '->filter() returns the event object'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $dispatcher->connect('foo', array($listener, 'filterFoo')); $e = $dispatcher->filter($event = new Event(new stdClass(), 'foo'), 'foo'); $t->is($e->getReturnValue(), '*-foo-*', '->filter() filters a value'); class Listener { protected $value = ''; function filterFoo(Event $event, $foo) { return "*{$foo}*"; } function filterFooBis(Event $event, $foo) { return "-{$foo}-"; } function listenToFoo(Event $event)
/** * Registers a core.response listener to add the Surrogate-Control header to a Response when needed. * * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher An EventDispatcher instance */ public function register(EventDispatcher $dispatcher) { if (null !== $this->esi) { $dispatcher->connect('core.response', array($this, 'filter')); } }
/** * Registers a core.exception listener. * * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher An EventDispatcher instance */ public function register(EventDispatcher $dispatcher) { $dispatcher->connect('core.exception', array($this, 'handle')); }
/** * Registers a core.request listener. * * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher An EventDispatcher instance */ public function register(EventDispatcher $dispatcher) { $dispatcher->connect('core.request', array($this, 'resolve')); }
/** * Registers a core.load_controller listener. * * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher An EventDispatcher instance */ public function register(EventDispatcher $dispatcher) { $dispatcher->connect('core.load_controller', array($this, 'resolve')); }
/** * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher */ public function register(EventDispatcher $dispatcher) { if (true === $this->enabled) { $dispatcher->connect('server.response', array($this, 'filter')); } }
/** * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher */ public function register(EventDispatcher $dispatcher) { $dispatcher->connect('server.request', array($this, 'handle')); }
/** * @param Symfony\Components\EventDispatcher\EventDispatcher $dispatcher */ public function register(EventDispatcher $dispatcher) { $dispatcher->connect('server.response', array($this, 'filter')); }