Symfony\Component\EventDispatcher\EventDispatcher::notifyUntil PHP Method

notifyUntil() public method

Notifies all listeners of a given event until one returns a non null value.
public notifyUntil ( Symfony\Component\EventDispatcher\Event $event ) : Symfony\Component\EventDispatcher\Event
$event Symfony\Component\EventDispatcher\Event An Event instance
return Symfony\Component\EventDispatcher\Event The Event instance
    public function notifyUntil(Event $event)
    {
        foreach ($this->getListeners($event->getName()) as $listener) {
            if (call_user_func($listener, $event)) {
                $event->setProcessed(true);
                break;
            }
        }

        return $event;
    }

Usage Example

Example #1
0
 public function testNotifyUntil()
 {
     $listener = new Listener();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'listenToFoo'));
     $dispatcher->connect('foo', array($listener, 'listenToFooBis'));
     $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo'));
     $this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops when the event is processed');
     $listener->reset();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'listenToFooBis'));
     $dispatcher->connect('foo', array($listener, 'listenToFoo'));
     $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo'));
     $this->assertEquals('listenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops when the event is processed');
 }