]> git.mxchange.org Git - friendica.git/blobdiff - src/App/Arguments.php
Merge pull request #11273 from MrPetovan/task/4639-soapbox-intro-notification
[friendica.git] / src / App / Arguments.php
index de3fecf9edbe476e92f6d2976304c10f2244f94e..4d386fc2551d2c5138e80db4e4fca53872fbcd7d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -30,6 +30,8 @@ namespace Friendica\App;
  */
 class Arguments
 {
+       const DEFAULT_MODULE = 'home';
+
        /**
         * @var string The complete query string
         */
@@ -38,6 +40,10 @@ class Arguments
         * @var string The current Friendica command
         */
        private $command;
+       /**
+        * @var string The name of the current module
+        */
+       private $moduleName;
        /**
         * @var array The arguments of the current execution
         */
@@ -46,13 +52,19 @@ class Arguments
         * @var int The count of arguments
         */
        private $argc;
+       /**
+        * @var string The used HTTP method
+        */
+       private $method;
 
-       public function __construct(string $queryString = '', string $command = '', array $argv = [], int $argc = 0)
+       public function __construct(string $queryString = '', string $command = '', string $moduleName = '', array $argv = [], int $argc = 0, string $method = Router::GET)
        {
                $this->queryString = $queryString;
                $this->command     = $command;
+               $this->moduleName  = $moduleName;
                $this->argv        = $argv;
                $this->argc        = $argc;
+               $this->method      = $method;
        }
 
        /**
@@ -71,6 +83,14 @@ class Arguments
                return $this->command;
        }
 
+       /**
+        * @return string The module name based on the arguments
+        */
+       public function getModuleName(): string
+       {
+               return $this->moduleName;
+       }
+
        /**
         * @return array All arguments of this call
         */
@@ -79,6 +99,14 @@ class Arguments
                return $this->argv;
        }
 
+       /**
+        * @return string The used HTTP method
+        */
+       public function getMethod()
+       {
+               return $this->method;
+       }
+
        /**
         * @return int The count of arguments of this call
         */
@@ -87,6 +115,17 @@ class Arguments
                return $this->argc;
        }
 
+       public function setArgv(array $argv)
+       {
+               $this->argv = $argv;
+               $this->argc = count($argv);
+       }
+
+       public function setArgc(int $argc)
+       {
+               $this->argc = $argc;
+       }
+
        /**
         * Returns the value of a argv key
         * @todo there are a lot of $a->argv usages in combination with ?? which can be replaced with this method
@@ -161,6 +200,20 @@ class Arguments
 
                $queryString = $command . ($queryParameters ? '?' . http_build_query($queryParameters) : '');
 
-               return new Arguments($queryString, $command, $argv, $argc);
+               if ($argc > 0) {
+                       $module = str_replace('.', '_', $argv[0]);
+                       $module = str_replace('-', '_', $module);
+               } else {
+                       $module = self::DEFAULT_MODULE;
+               }
+
+               // Compatibility with the Firefox App
+               if (($module == "users") && ($command == "users/sign_in")) {
+                       $module = "login";
+               }
+
+               $httpMethod = in_array($server['REQUEST_METHOD'] ?? '', Router::ALLOWED_METHODS) ? $server['REQUEST_METHOD'] : Router::GET;
+
+               return new Arguments($queryString, $command, $module, $argv, $argc, $httpMethod);
        }
 }