8.5.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)
8.0.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)
8.1.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)
8.2.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)
8.3.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)
8.4.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)
8.6.x EventDispatcher.php EventDispatcher::addListener($eventName, $listener, $priority = 0)

Adds an event listener that listens on the specified events.

Parameters

string $eventName The event to listen on:

callable $listener The listener:

int $priority The higher this value, the earlier an event: listener will be triggered in the chain (defaults to 0)

Overrides EventDispatcherInterface::addListener

2 calls to EventDispatcher::addListener()
ContainerAwareEventDispatcher::lazyLoad in vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php
Lazily loads listeners for this event from the dependency injection container.
EventDispatcher::addSubscriber in vendor/symfony/event-dispatcher/EventDispatcher.php
Adds an event subscriber.

File

vendor/symfony/event-dispatcher/EventDispatcher.php, line 112

Class

EventDispatcher
The EventDispatcherInterface is the central point of Symfony's event listener system.

Namespace

Symfony\Component\EventDispatcher

Code

public function addListener($eventName, $listener, $priority = 0) {
  $this->listeners[$eventName][$priority][] = $listener;
  unset($this->sorted[$eventName]);
}