]> git.mxchange.org Git - friendica.git/blobdiff - src/App/Module.php
Creating interfaces for Config/PConfig & fix tests
[friendica.git] / src / App / Module.php
index 33a9b2fc2f33d91d0a2754f38448f15999322072..7c81b6a7eaac2a9797b6e4baf11367f8463313b0 100644 (file)
@@ -3,7 +3,7 @@
 namespace Friendica\App;
 
 use Friendica\App;
-use Friendica\BaseObject;
+use Friendica\BaseModule;
 use Friendica\Core;
 use Friendica\LegacyModule;
 use Friendica\Module\Home;
@@ -59,10 +59,15 @@ class Module
        private $module;
 
        /**
-        * @var BaseObject The module class
+        * @var BaseModule The module class
         */
        private $module_class;
 
+       /**
+        * @var array The module parameters
+        */
+       private $module_parameters;
+
        /**
         * @var bool true, if the module is a backend module
         */
@@ -89,6 +94,14 @@ class Module
                return $this->module_class;
        }
 
+       /**
+        * @return array The module parameters extracted from the route
+        */
+       public function getParameters()
+       {
+               return $this->module_parameters;
+       }
+
        /**
         * @return bool True, if the current module is a backend module
         * @see Module::BACKEND_MODULES for a list
@@ -98,10 +111,11 @@ class Module
                return $this->isBackend;
        }
 
-       public function __construct(string $module = self::DEFAULT, string $moduleClass = self::DEFAULT_CLASS, bool $isBackend = false, bool $printNotAllowedAddon = false)
+       public function __construct(string $module = self::DEFAULT, string $moduleClass = self::DEFAULT_CLASS, array $moduleParameters = [], bool $isBackend = false, bool $printNotAllowedAddon = false)
        {
                $this->module               = $module;
                $this->module_class         = $moduleClass;
+               $this->module_parameters    = $moduleParameters;
                $this->isBackend            = $isBackend;
                $this->printNotAllowedAddon = $printNotAllowedAddon;
        }
@@ -129,7 +143,7 @@ class Module
 
                $isBackend = in_array($module, Module::BACKEND_MODULES);;
 
-               return new Module($module, $this->module_class, $isBackend, $this->printNotAllowedAddon);
+               return new Module($module, $this->module_class, [], $isBackend, $this->printNotAllowedAddon);
        }
 
        /**
@@ -137,17 +151,18 @@ class Module
         *
         * @param Arguments                 $args   The Friendica execution arguments
         * @param Router                    $router The Friendica routing instance
-        * @param Core\Config\Configuration $config The Friendica Configuration
+        * @param Core\Config\IConfiguration $config The Friendica Configuration
         *
         * @return Module The determined module of this call
         *
         * @throws \Exception
         */
-       public function determineClass(Arguments $args, Router $router, Core\Config\Configuration $config)
+       public function determineClass(Arguments $args, Router $router, Core\Config\IConfiguration $config)
        {
                $printNotAllowedAddon = false;
 
                $module_class = null;
+               $module_parameters = [];
                /**
                 * ROUTING
                 *
@@ -156,6 +171,7 @@ class Module
                 **/
                try {
                        $module_class = $router->getModuleClass($args->getCommand());
+                       $module_parameters = $router->getModuleParameters();
                } catch (MethodNotAllowedException $e) {
                        $module_class = MethodNotAllowed::class;
                } catch (NotFoundException $e) {
@@ -185,21 +201,21 @@ class Module
                        $module_class = $module_class ?: PageNotFound::class;
                }
 
-               return new Module($this->module, $module_class, $this->isBackend, $printNotAllowedAddon);
+               return new Module($this->module, $module_class, $module_parameters, $this->isBackend, $printNotAllowedAddon);
        }
 
        /**
         * Run the determined module class and calls all hooks applied to
         *
         * @param Core\L10n\L10n  $l10n         The L10n instance
-        * @param App             $app          The whole Friendica app (for method arguments)
+        * @param App\BaseURL     $baseUrl      The Friendica Base URL
         * @param LoggerInterface $logger       The Friendica logger
         * @param array           $server       The $_SERVER variable
         * @param array           $post         The $_POST variables
         *
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function run(Core\L10n\L10n $l10n, App $app, LoggerInterface $logger, array $server, array $post)
+       public function run(Core\L10n\L10n $l10n, App\BaseURL $baseUrl, LoggerInterface $logger, array $server, array $post)
        {
                if ($this->printNotAllowedAddon) {
                        info($l10n->t("You must be logged in to use addons. "));
@@ -223,7 +239,7 @@ class Module
 
                        if (!empty($queryString) && ($queryString === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
                                $logger->info('index.php: dreamhost_error_hack invoked.', ['Original URI' => $server['REQUEST_URI']]);
-                               $app->internalRedirect($server['REQUEST_URI']);
+                               $baseUrl->redirect($server['REQUEST_URI']);
                        }
 
                        $logger->debug('index.php: page not found.', ['request_uri' => $server['REQUEST_URI'], 'address' => $server['REMOTE_ADDR'], 'query' => $server['QUERY_STRING']]);
@@ -233,18 +249,18 @@ class Module
 
                Core\Hook::callAll($this->module . '_mod_init', $placeholder);
 
-               call_user_func([$this->module_class, 'init']);
-
-               // "rawContent" is especially meant for technical endpoints.
-               // This endpoint doesn't need any theme initialization or other comparable stuff.
-               call_user_func([$this->module_class, 'rawContent']);
+               call_user_func([$this->module_class, 'init'], $this->module_parameters);
 
                if ($server['REQUEST_METHOD'] === 'POST') {
                        Core\Hook::callAll($this->module . '_mod_post', $post);
-                       call_user_func([$this->module_class, 'post']);
+                       call_user_func([$this->module_class, 'post'], $this->module_parameters);
                }
 
                Core\Hook::callAll($this->module . '_mod_afterpost', $placeholder);
-               call_user_func([$this->module_class, 'afterpost']);
+               call_user_func([$this->module_class, 'afterpost'], $this->module_parameters);
+
+               // "rawContent" is especially meant for technical endpoints.
+               // This endpoint doesn't need any theme initialization or other comparable stuff.
+               call_user_func([$this->module_class, 'rawContent'], $this->module_parameters);
        }
 }