]> git.mxchange.org Git - friendica.git/commitdiff
Implement home_init hook as Event
authorArt4 <art4@wlabs.de>
Sat, 8 Feb 2025 16:33:07 +0000 (16:33 +0000)
committerArt4 <art4@wlabs.de>
Sat, 8 Feb 2025 16:33:07 +0000 (16:33 +0000)
src/Core/Hooks/HookEventBridge.php
src/Event/Event.php
src/Module/Home.php
src/Module/User/Delegation.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php

index 306434609bff5e03c032a4a9787e44fdffdff4f8..9f35828ebfd686df32a4ae464a03f88ec7179293 100644 (file)
@@ -35,6 +35,7 @@ final class HookEventBridge
         */
        private static array $eventMapper = [
                Event::INIT                        => 'init_1',
+               Event::HOME_INIT                   => 'home_init',
                ConfigLoadedEvent::CONFIG_LOADED   => 'load_config',
                ArrayFilterEvent::APP_MENU         => 'app_menu',
                ArrayFilterEvent::NAV_INFO         => 'nav_info',
@@ -57,6 +58,7 @@ final class HookEventBridge
        {
                return [
                        Event::INIT                        => 'onNamedEvent',
+                       Event::HOME_INIT                   => 'onNamedEvent',
                        ConfigLoadedEvent::CONFIG_LOADED   => 'onConfigLoadedEvent',
                        ArrayFilterEvent::APP_MENU         => 'onArrayFilterEvent',
                        ArrayFilterEvent::NAV_INFO         => 'onArrayFilterEvent',
index 90defc32048c831bca98a24d494448d06e013cdd..7a6fca38400c1780a655de5b5f1ea0608f523adc 100644 (file)
@@ -21,6 +21,8 @@ class Event implements NamedEvent
         */
        public const INIT = 'friendica.init';
 
+       public const HOME_INIT = 'friendica.home_init';
+
        private string $name;
 
        public function __construct(string $name)
index 9c72398f7a685ff26482628685b2f137a94e2d06..692d10ba5f6300674d72a84192d622a490b52cc5 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\BaseModule;
 use Friendica\Core\Hook;
 use Friendica\Core\Renderer;
 use Friendica\DI;
+use Friendica\Event\Event;
 use Friendica\Model\User;
 use Friendica\Module\Security\Login;
 use Friendica\Protocol\ActivityPub;
@@ -34,11 +35,11 @@ class Home extends BaseModule
        {
                $basePath = DI::appHelper()->getBasePath();
                $config = DI::config();
+               $eventDispatcher = DI::eventDispatcher();
 
-               // currently no returned data is used
-               $ret = [];
-
-               Hook::callAll('home_init', $ret);
+               $eventDispatcher->dispatch(
+                       new Event(Event::HOME_INIT)
+               );
 
                if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserNickname())) {
                        DI::baseUrl()->redirect('network');
index 2c138913482a3d4f4c0f8a70ceba208b9042b628..1658e72c18873dab3970471e0817322abda766df 100644 (file)
@@ -12,11 +12,11 @@ use Friendica\App\BaseURL;
 use Friendica\AppHelper;
 use Friendica\BaseModule;
 use Friendica\Contact\Introduction\Repository\Introduction;
-use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Database\Database;
+use Friendica\Event\Event;
 use Friendica\Model\Notification;
 use Friendica\Model\User;
 use Friendica\Module\Response;
@@ -25,6 +25,7 @@ use Friendica\Navigation\SystemMessages;
 use Friendica\Network\HTTPException\ForbiddenException;
 use Friendica\Security\Authentication;
 use Friendica\Util;
+use Psr\EventDispatcher\EventDispatcherInterface;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -46,8 +47,9 @@ class Delegation extends BaseModule
        private $intro;
        /** @var AppHelper */
        private $appHelper;
+       private EventDispatcherInterface $eventDispatcher;
 
-       public function __construct(AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
+       public function __construct(EventDispatcherInterface $eventDispatcher, AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
@@ -58,6 +60,7 @@ class Delegation extends BaseModule
                $this->notify         = $notify;
                $this->intro          = $intro;
                $this->appHelper      = $appHelper;
+               $this->eventDispatcher = $eventDispatcher;
        }
 
        protected function post(array $request = [])
@@ -128,8 +131,9 @@ class Delegation extends BaseModule
                        $this->session->setSubManagedUserId($original_id);
                }
 
-               $ret = [];
-               Hook::callAll('home_init', $ret);
+               $this->eventDispatcher->dispatch(
+                       new Event(Event::HOME_INIT)
+               );
 
                $this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
 
index 8a207684b1e85fa91789511cc5ee06f3eedc7151..6e82ab09f613de599825e683a6f4bb38cb65c94f 100644 (file)
@@ -23,6 +23,7 @@ class HookEventBridgeTest extends TestCase
        {
                $expected = [
                        Event::INIT                        => 'onNamedEvent',
+                       Event::HOME_INIT                   => 'onNamedEvent',
                        ConfigLoadedEvent::CONFIG_LOADED   => 'onConfigLoadedEvent',
                        ArrayFilterEvent::APP_MENU         => 'onArrayFilterEvent',
                        ArrayFilterEvent::NAV_INFO         => 'onArrayFilterEvent',
@@ -61,6 +62,7 @@ class HookEventBridgeTest extends TestCase
                return [
                        ['test', 'test'],
                        [Event::INIT, 'init_1'],
+                       [Event::HOME_INIT, 'home_init'],
                ];
        }