Refactor HookEventBridge

This commit is contained in:
Art4 2025-01-28 07:23:44 +00:00 committed by Hypolite Petovan
parent 16fb80be1f
commit 4cbee618d6

View file

@ -58,31 +58,19 @@ final class HookEventBridge
public static function onNamedEvent(NamedEvent $event): void public static function onNamedEvent(NamedEvent $event): void
{ {
$name = $event->getName(); static::callHook($event->getName(), '');
$name = static::$eventMapper[$name] ?? $name;
static::callHook($name, '');
}
public static function onHtmlFilterEvent(HtmlFilterEvent $event): void
{
$name = $event->getName();
$name = static::$eventMapper[$name] ?? $name;
$event->setHtml(
static::callHook($name, $event->getHtml())
);
} }
public static function onConfigLoadedEvent(ConfigLoadedEvent $event): void public static function onConfigLoadedEvent(ConfigLoadedEvent $event): void
{ {
$name = $event->getName(); static::callHook($event->getName(), $event->getConfig());
}
$name = static::$eventMapper[$name] ?? $name; public static function onHtmlFilterEvent(HtmlFilterEvent $event): void
{
static::callHook($name, $event->getConfig()); $event->setHtml(
static::callHook($event->getName(), $event->getHtml())
);
} }
/** /**
@ -92,6 +80,9 @@ final class HookEventBridge
*/ */
private static function callHook(string $name, $data) private static function callHook(string $name, $data)
{ {
// If possible, map the event name to the legacy Hook name
$name = static::$eventMapper[$name] ?? $name;
// Little hack to allow mocking the Hook call in tests. // Little hack to allow mocking the Hook call in tests.
if (static::$mockedCallHook instanceof \Closure) { if (static::$mockedCallHook instanceof \Closure) {
return (static::$mockedCallHook)->__invoke($name, $data); return (static::$mockedCallHook)->__invoke($name, $data);