diff --git a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php index caead14..76016b7 100644 --- a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -62,11 +62,11 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface { protected $listeners; /** - * Whether event listeners are ordered, keyed by event name. + * Whether listeners need to be sorted prior to dispatch, keyed by event name. * * @var TRUE[] */ - protected $sorted; + protected $unsorted; /** * Constructs a container aware event dispatcher. @@ -85,7 +85,7 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface { public function __construct(IntrospectableContainerInterface $container, array $listeners = []) { $this->container = $container; $this->listeners = $listeners; - $this->sorted = array_fill_keys(array_keys($this->listeners), TRUE); + $this->unsorted = []; } /** @@ -101,9 +101,9 @@ public function dispatch($event_name, Event $event = NULL) { if (isset($this->listeners[$event_name])) { // Sort listeners if necessary. - if (!isset($this->sorted[$event_name])) { + if (isset($this->unsorted[$event_name])) { krsort($this->listeners[$event_name]); - $this->sorted[$event_name] = TRUE; + unset($this->unsorted[$event_name]); } // Invoke listeners and resolve callables if necessary. @@ -141,9 +141,9 @@ public function getListeners($event_name = NULL) { } elseif (isset($this->listeners[$event_name])) { // Sort listeners if necessary. - if (!isset($this->sorted[$event_name])) { + if (isset($this->unsorted[$event_name])) { krsort($this->listeners[$event_name]); - $this->sorted[$event_name] = TRUE; + unset($this->unsorted[$event_name]); } // Collect listeners and resolve callables if necessary. @@ -173,7 +173,7 @@ public function hasListeners($event_name = NULL) { */ public function addListener($event_name, $listener, $priority = 0) { $this->listeners[$event_name][$priority][] = ['callable' => $listener]; - unset($this->sorted[$event_name]); + $this->unsorted[$event_name] = TRUE; } /**