ContainerAwareEventDispatcher
class ContainerAwareEventDispatcher implements EventDispatcherInterface (View source)
A performance optimized container aware event dispatcher.
This version of the event dispatcher contains the following optimizations in comparison to the Symfony event dispatcher component:
- Faster instantiation of the event dispatcher service
- Instead of calling ```addSubscriberService``` once for each subscriber, a precompiled array of listener definitions is passed directly to the constructor. This is faster by roughly an order of magnitude. The listeners are collected and prepared using a compiler pass.
- Lazy instantiation of listeners
- Services are only retrieved from the container just before invocation. Especially when dispatching the KernelEvents::REQUEST event, this leads to a more timely invocation of the first listener. Overall dispatch runtime is not affected by this change though.
Properties
| protected ContainerInterface | $container | The service container. |
|
| protected array | $listeners | Listener definitions. |
|
| protected true[] | $unsorted | Whether listeners need to be sorted prior to dispatch, keyed by event name. |
Methods
__construct(ContainerInterface $container, array $listeners = [])
Constructs a container aware event dispatcher.
dispatch($event)
{@inheritdoc}
array
getListeners($event_name = NULL)
{@inheritdoc}
int|null
getListenerPriority($event_name, $listener)
{@inheritdoc}
bool
hasListeners($event_name = NULL)
{@inheritdoc}
addListener($event_name, $listener, $priority = 0)
{@inheritdoc}
removeListener($event_name, $listener)
{@inheritdoc}
addSubscriber(EventSubscriberInterface $subscriber)
{@inheritdoc}
removeSubscriber(EventSubscriberInterface $subscriber)
{@inheritdoc}
Details
__construct(ContainerInterface $container, array $listeners = [])
Constructs a container aware event dispatcher.
dispatch($event)
{@inheritdoc}
array
getListeners($event_name = NULL)
{@inheritdoc}
int|null
getListenerPriority($event_name, $listener)
{@inheritdoc}
bool
hasListeners($event_name = NULL)
{@inheritdoc}
addListener($event_name, $listener, $priority = 0)
{@inheritdoc}
removeListener($event_name, $listener)
{@inheritdoc}
addSubscriber(EventSubscriberInterface $subscriber)
{@inheritdoc}
removeSubscriber(EventSubscriberInterface $subscriber)
{@inheritdoc}