Symfony\Component\EventDispatcher\EventDispatcher::notify PHP Метод

notify() публичный Метод

Notifies all listeners of a given event.
public notify ( Symfony\Component\EventDispatcher\Event $event ) : Symfony\Component\EventDispatcher\Event
$event Symfony\Component\EventDispatcher\Event An Event instance
Результат Symfony\Component\EventDispatcher\Event The Event instance
    public function notify(Event $event)
    {
        foreach ($this->getListeners($event->getName()) as $listener) {
            call_user_func($listener, $event);
        }

        return $event;
    }

Usage Example

Пример #1
0
 public function testNotify()
 {
     $listener = new Listener();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'listenToFoo'));
     $dispatcher->connect('foo', array($listener, 'listenToFooBis'));
     $e = $dispatcher->notify($event = new Event(new \stdClass(), 'foo'));
     $this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notify() notifies all registered listeners in order');
     $listener->reset();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'listenToFooBis'));
     $dispatcher->connect('foo', array($listener, 'listenToFoo'));
     $dispatcher->notify(new Event(new \stdClass(), 'foo'));
     $this->assertEquals('listenToFooBislistenToFoo', $listener->getValue(), '->notify() notifies all registered listeners in order');
 }