Skip to content

Commit

Permalink
[EventDispatcher] skip one lazy loading call
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Sep 17, 2015
1 parent ec59953 commit a7b7f54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
Expand Up @@ -103,7 +103,7 @@ public function removeListener($eventName, $listener)
}

/**
* @see EventDispatcherInterface::hasListeners()
* {@inheritdoc}
*/
public function hasListeners($eventName = null)
{
Expand All @@ -119,7 +119,7 @@ public function hasListeners($eventName = null)
}

/**
* @see EventDispatcherInterface::getListeners()
* {@inheritdoc}
*/
public function getListeners($eventName = null)
{
Expand Down Expand Up @@ -155,21 +155,6 @@ public function addSubscriberService($serviceId, $class)
}
}

/**
* {@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()
{
return $this->container;
Expand Down
26 changes: 9 additions & 17 deletions src/Symfony/Component/EventDispatcher/EventDispatcher.php
Expand Up @@ -33,9 +33,7 @@ class EventDispatcher implements EventDispatcherInterface
private $sorted = array();

/**
* @see EventDispatcherInterface::dispatch()
*
* @api
* {@inheritdoc}
*/
public function dispatch($eventName, Event $event = null)
{
Expand All @@ -46,17 +44,15 @@ public function dispatch($eventName, Event $event = null)
$event->setDispatcher($this);
$event->setName($eventName);

if (!isset($this->listeners[$eventName])) {
return $event;
if ($listeners = $this->getListeners($eventName)) {
$this->doDispatch($listeners, $eventName, $event);
}

$this->doDispatch($this->getListeners($eventName), $eventName, $event);

return $event;
}

/**
* @see EventDispatcherInterface::getListeners()
* {@inheritdoc}
*/
public function getListeners($eventName = null)
{
Expand All @@ -82,17 +78,15 @@ public function getListeners($eventName = null)
}

/**
* @see EventDispatcherInterface::hasListeners()
* {@inheritdoc}
*/
public function hasListeners($eventName = null)
{
return (bool) count($this->getListeners($eventName));
}

/**
* @see EventDispatcherInterface::addListener()
*
* @api
* {@inheritdoc}
*/
public function addListener($eventName, $listener, $priority = 0)
{
Expand All @@ -101,7 +95,7 @@ public function addListener($eventName, $listener, $priority = 0)
}

/**
* @see EventDispatcherInterface::removeListener()
* {@inheritdoc}
*/
public function removeListener($eventName, $listener)
{
Expand All @@ -117,9 +111,7 @@ public function removeListener($eventName, $listener)
}

/**
* @see EventDispatcherInterface::addSubscriber()
*
* @api
* {@inheritdoc}
*/
public function addSubscriber(EventSubscriberInterface $subscriber)
{
Expand All @@ -137,7 +129,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber)
}

/**
* @see EventDispatcherInterface::removeSubscriber()
* {@inheritdoc}
*/
public function removeSubscriber(EventSubscriberInterface $subscriber)
{
Expand Down

0 comments on commit a7b7f54

Please sign in to comment.