From b979931a026531f395805d730440b3a53ae3a8d8 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 17 Jun 2021 07:03:59 +0200 Subject: [PATCH] Add `EventHandler::executeListeners()` Instead of having the same code in `EventHandler::executeInheritedActions()` and `EventHandler::fireAction()`, it is now just in one method. --- .../lib/system/event/EventHandler.class.php | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/wcfsetup/install/files/lib/system/event/EventHandler.class.php b/wcfsetup/install/files/lib/system/event/EventHandler.class.php index 685df35398..003d89aa05 100644 --- a/wcfsetup/install/files/lib/system/event/EventHandler.class.php +++ b/wcfsetup/install/files/lib/system/event/EventHandler.class.php @@ -124,18 +124,13 @@ class EventHandler extends SingletonFactory } } - // execute actions - foreach ($this->inheritedActionsObjects[$name] as $actionObj) { - if ($actionObj instanceof IParameterizedEventListener) { - $actionObj->execute($eventObj, $className, $eventName, $parameters); - - if (!\is_array($parameters)) { - throw new SystemException("'" . \get_class($actionObj) . "' breaks the '\$parameters' array!"); - } - } elseif ($actionObj instanceof ILegacyEventListener) { - $actionObj->execute($eventObj, $className, $eventName); - } - } + $this->executeListeners( + $this->inheritedActionsObjects[$name], + $eventObj, + $className, + $eventName, + $parameters + ); } /** @@ -166,6 +161,30 @@ class EventHandler extends SingletonFactory return $object; } + /** + * @param EventListener[] $eventListeners + * @since 5.5 + */ + protected function executeListeners( + array $eventListeners, + $eventObj, + string $className, + string $eventName, + array &$parameters + ): void { + foreach ($eventListeners as $actionObj) { + if ($actionObj instanceof IParameterizedEventListener) { + $actionObj->execute($eventObj, $className, $eventName, $parameters); + + if (!\is_array($parameters)) { + throw new SystemException("'" . \get_class($actionObj) . "' breaks the '\$parameters' array!"); + } + } elseif ($actionObj instanceof ILegacyEventListener) { + $actionObj->execute($eventObj, $className, $eventName); + } + } + } + /** * Executes all registered listeners for the given event. * @@ -221,18 +240,13 @@ class EventHandler extends SingletonFactory } } - // execute actions - foreach ($this->actionsObjects[$name] as $actionObj) { - if ($actionObj instanceof IParameterizedEventListener) { - $actionObj->execute($eventObj, $className, $eventName, $parameters); - - if (!\is_array($parameters)) { - throw new SystemException("'" . \get_class($actionObj) . "' breaks the '\$parameters' array!"); - } - } elseif ($actionObj instanceof ILegacyEventListener) { - $actionObj->execute($eventObj, $className, $eventName); - } - } + $this->executeListeners( + $this->actionsObjects[$name], + $eventObj, + $className, + $eventName, + $parameters + ); } /** -- 2.20.1