From 4edc9e3565a172527949bae515809fafb1eeff32 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 20 May 2020 19:04:00 +0200 Subject: [PATCH] Dynamic event listener with extra support for DBOActions --- .../listener/AbstractEventListener.class.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/event/listener/AbstractEventListener.class.php diff --git a/wcfsetup/install/files/lib/system/event/listener/AbstractEventListener.class.php b/wcfsetup/install/files/lib/system/event/listener/AbstractEventListener.class.php new file mode 100644 index 0000000000..c12c0a5f67 --- /dev/null +++ b/wcfsetup/install/files/lib/system/event/listener/AbstractEventListener.class.php @@ -0,0 +1,48 @@ + + * @package WoltLabSuite\Core\System\Event\Listener + */ +abstract class AbstractEventListener implements IParameterizedEventListener { + /** + * @inheritDoc + */ + public final function execute($eventObj, $className, $eventName, array &$parameters) { + static $genericDboActionNames = ['finalizeAction', 'initializeAction', 'validateAction']; + + $methodName = 'on' . ucfirst($eventName); + + if ($eventObj instanceof AbstractDatabaseObjectAction && in_array($eventName, $genericDboActionNames)) { + $actionMethod = $methodName . ucfirst($eventObj->getActionName()); + if (method_exists($this, $actionMethod)) { + $this->{$actionMethod}($eventObj, $parameters); + return; + } + } + + if (method_exists($this, $methodName)) { + $this->{$methodName}($eventObj, $parameters); + } + } +} -- 2.20.1