From: Matthias Schmidt Date: Thu, 17 Jun 2021 05:03:59 +0000 (+0200) Subject: Add `EventHandler::executeListeners()` X-Git-Tag: 5.5.0_Alpha_1~633^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b979931a026531f395805d730440b3a53ae3a8d8;p=GitHub%2FWoltLab%2FWCF.git Add `EventHandler::executeListeners()` Instead of having the same code in `EventHandler::executeInheritedActions()` and `EventHandler::fireAction()`, it is now just in one method. --- 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 + ); } /**