mirror of
https://github.com/friendica/friendica
synced 2025-02-16 06:14:01 +00:00
Refactor HookEventBridge
This commit is contained in:
parent
16fb80be1f
commit
4cbee618d6
1 changed files with 11 additions and 20 deletions
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue