continue;
}
- // get class object
- if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
- $object = $this->listenerObjects[$eventListener->listenerClassName];
- } else {
- $object = null;
- // instance action object
- if (!\class_exists($eventListener->listenerClassName)) {
- throw new SystemException("Unable to find class '" . $eventListener->listenerClassName . "'");
- }
- if (
- !\is_subclass_of(
- $eventListener->listenerClassName,
- IParameterizedEventListener::class
- )
- ) {
- // legacy event listeners
- if (
- !\is_subclass_of(
- $eventListener->listenerClassName,
- IEventListener::class
- )
- ) {
- throw new ImplementationException(
- $eventListener->listenerClassName,
- IParameterizedEventListener::class
- );
- }
- }
-
- $object = new $eventListener->listenerClassName();
- $this->listenerObjects[$eventListener->listenerClassName] = $object;
- }
-
- if ($object !== null) {
- $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $object;
- }
+ $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $this->getListenerObject($eventListener);
}
}
}
}
}
+ /**
+ * @since 5.5
+ */
+ protected function getListenerObject(EventListener $eventListener): object
+ {
+ if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
+ return $this->listenerObjects[$eventListener->listenerClassName];
+ }
+
+ if (!\class_exists($eventListener->listenerClassName)) {
+ throw new SystemException("Unable to find class '" . $eventListener->listenerClassName . "'");
+ }
+ if (
+ !\is_subclass_of($eventListener->listenerClassName, IParameterizedEventListener::class)
+ && !\is_subclass_of($eventListener->listenerClassName, IEventListener::class)
+ ) {
+ throw new ImplementationException(
+ $eventListener->listenerClassName,
+ IParameterizedEventListener::class
+ );
+ }
+
+ $object = new $eventListener->listenerClassName();
+ $this->listenerObjects[$eventListener->listenerClassName] = $object;
+
+ return $object;
+ }
+
/**
* Executes all registered listeners for the given event.
*
continue;
}
- // get class object
- if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
- $object = $this->listenerObjects[$eventListener->listenerClassName];
- } else {
- // instance action object
- if (!\class_exists($eventListener->listenerClassName)) {
- throw new SystemException("Unable to find class '" . $eventListener->listenerClassName . "'");
- }
- if (!\is_subclass_of($eventListener->listenerClassName, IParameterizedEventListener::class)) {
- // legacy event listeners
- if (!\is_subclass_of($eventListener->listenerClassName, IEventListener::class)) {
- throw new ImplementationException(
- $eventListener->listenerClassName,
- IParameterizedEventListener::class
- );
- }
- }
-
- $object = new $eventListener->listenerClassName();
- $this->listenerObjects[$eventListener->listenerClassName] = $object;
- }
-
- $this->actionsObjects[$name][$eventListener->listenerClassName] = $object;
+ $this->actionsObjects[$name][$eventListener->listenerClassName] = $this->getListenerObject($eventListener);
}
}
}