[EventDispatcher] skip one lazy loading call

This commit is contained in:
Tobias Schultze 2015-09-17 03:42:05 +02:00
parent ec59953f4c
commit a7b7f5479e
2 changed files with 11 additions and 34 deletions

View File

@ -103,7 +103,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
} }
/** /**
* @see EventDispatcherInterface::hasListeners() * {@inheritdoc}
*/ */
public function hasListeners($eventName = null) public function hasListeners($eventName = null)
{ {
@ -119,7 +119,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
} }
/** /**
* @see EventDispatcherInterface::getListeners() * {@inheritdoc}
*/ */
public function getListeners($eventName = null) public function getListeners($eventName = null)
{ {
@ -155,21 +155,6 @@ class ContainerAwareEventDispatcher extends EventDispatcher
} }
} }
/**
* {@inheritdoc}
*
* Lazily loads listeners for this event from the dependency injection
* container.
*
* @throws \InvalidArgumentException if the service is not defined
*/
public function dispatch($eventName, Event $event = null)
{
$this->lazyLoad($eventName);
return parent::dispatch($eventName, $event);
}
public function getContainer() public function getContainer()
{ {
return $this->container; return $this->container;

View File

@ -33,9 +33,7 @@ class EventDispatcher implements EventDispatcherInterface
private $sorted = array(); private $sorted = array();
/** /**
* @see EventDispatcherInterface::dispatch() * {@inheritdoc}
*
* @api
*/ */
public function dispatch($eventName, Event $event = null) public function dispatch($eventName, Event $event = null)
{ {
@ -46,17 +44,15 @@ class EventDispatcher implements EventDispatcherInterface
$event->setDispatcher($this); $event->setDispatcher($this);
$event->setName($eventName); $event->setName($eventName);
if (!isset($this->listeners[$eventName])) { if ($listeners = $this->getListeners($eventName)) {
return $event; $this->doDispatch($listeners, $eventName, $event);
} }
$this->doDispatch($this->getListeners($eventName), $eventName, $event);
return $event; return $event;
} }
/** /**
* @see EventDispatcherInterface::getListeners() * {@inheritdoc}
*/ */
public function getListeners($eventName = null) public function getListeners($eventName = null)
{ {
@ -82,7 +78,7 @@ class EventDispatcher implements EventDispatcherInterface
} }
/** /**
* @see EventDispatcherInterface::hasListeners() * {@inheritdoc}
*/ */
public function hasListeners($eventName = null) public function hasListeners($eventName = null)
{ {
@ -90,9 +86,7 @@ class EventDispatcher implements EventDispatcherInterface
} }
/** /**
* @see EventDispatcherInterface::addListener() * {@inheritdoc}
*
* @api
*/ */
public function addListener($eventName, $listener, $priority = 0) public function addListener($eventName, $listener, $priority = 0)
{ {
@ -101,7 +95,7 @@ class EventDispatcher implements EventDispatcherInterface
} }
/** /**
* @see EventDispatcherInterface::removeListener() * {@inheritdoc}
*/ */
public function removeListener($eventName, $listener) public function removeListener($eventName, $listener)
{ {
@ -117,9 +111,7 @@ class EventDispatcher implements EventDispatcherInterface
} }
/** /**
* @see EventDispatcherInterface::addSubscriber() * {@inheritdoc}
*
* @api
*/ */
public function addSubscriber(EventSubscriberInterface $subscriber) public function addSubscriber(EventSubscriberInterface $subscriber)
{ {
@ -137,7 +129,7 @@ class EventDispatcher implements EventDispatcherInterface
} }
/** /**
* @see EventDispatcherInterface::removeSubscriber() * {@inheritdoc}
*/ */
public function removeSubscriber(EventSubscriberInterface $subscriber) public function removeSubscriber(EventSubscriberInterface $subscriber)
{ {