filter() public method

Filters a value by calling all listeners of a given event.
public filter ( Symfony\Component\EventDispatcher\Event $event, mixed $value ) : Symfony\Component\EventDispatcher\Event
$event Symfony\Component\EventDispatcher\Event An Event instance
$value mixed The value to be filtered
return Symfony\Component\EventDispatcher\Event The Event instance
Example #1
0
 public function testFilterWhenThereIsNoEsiIncludes()
 {
     $dispatcher = new EventDispatcher();
     $listener = new EsiListener(new Esi());
     $dispatcher->connect('core.response', array($listener, 'filter'));
     $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST));
     $dispatcher->filter($event, $response = new Response('foo'));
     $this->assertEquals('', $response->headers->get('Surrogate-Control'));
 }
Example #2
0
 public function testFilter()
 {
     $listener = new Listener();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'filterFoo'));
     $dispatcher->connect('foo', array($listener, 'filterFooBis'));
     $ret = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
     $this->assertEquals('-*foo*-', $ret, '->filter() returns the filtered value');
     $listener->reset();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'filterFooBis'));
     $dispatcher->connect('foo', array($listener, 'filterFoo'));
     $ret = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
     $this->assertEquals('*-foo-*', $ret, '->filter() returns the filtered value');
 }
 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');
 }