|
@@ -71,6 +71,38 @@ class ContainerAwareEventDispatcher extends EventDispatcher
|
|
|
$this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @see EventDispatcherInterface::hasListeners
|
|
|
+ */
|
|
|
+ public function hasListeners($eventName = null)
|
|
|
+ {
|
|
|
+ if (null === $eventName) {
|
|
|
+ return (Boolean) count($this->listenerIds) || (Boolean) count($this->listeners);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($this->listenerIds[$eventName])) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return parent::hasListeners($eventName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see EventDispatcherInterface::getListeners
|
|
|
+ */
|
|
|
+ public function getListeners($eventName = null)
|
|
|
+ {
|
|
|
+ if (null === $eventName) {
|
|
|
+ foreach ($this->listenerIds as $serviceEventName => $listners) {
|
|
|
+ $this->lazyLoad($serviceEventName);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->lazyLoad($eventName);
|
|
|
+ }
|
|
|
+
|
|
|
+ return parent::getListeners($eventName);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {@inheritDoc}
|
|
|
*
|
|
@@ -80,6 +112,21 @@ class ContainerAwareEventDispatcher extends EventDispatcher
|
|
|
* @throws \InvalidArgumentException if the service is not defined
|
|
|
*/
|
|
|
public function dispatch($eventName, Event $event = null)
|
|
|
+ {
|
|
|
+ $this->lazyLoad($eventName);
|
|
|
+
|
|
|
+ parent::dispatch($eventName, $event);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Lazily loads listeners for this event from the dependency injection
|
|
|
+ * container.
|
|
|
+ *
|
|
|
+ * @param string $eventName The name of the event to dispatch. The name of
|
|
|
+ * the event is the name of the method that is
|
|
|
+ * invoked on listeners.
|
|
|
+ */
|
|
|
+ protected function lazyLoad($eventName)
|
|
|
{
|
|
|
if (isset($this->listenerIds[$eventName])) {
|
|
|
foreach ($this->listenerIds[$eventName] as $args) {
|
|
@@ -97,7 +144,5 @@ class ContainerAwareEventDispatcher extends EventDispatcher
|
|
|
$this->listeners[$eventName][$key] = $listener;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- parent::dispatch($eventName, $event);
|
|
|
}
|
|
|
}
|