]> git.mxchange.org Git - friendica.git/commitdiff
Use Args::getMethod() at various places
authorPhilipp <admin@philipp.info>
Sun, 2 Jan 2022 21:25:50 +0000 (22:25 +0100)
committerPhilipp <admin@philipp.info>
Tue, 4 Jan 2022 19:59:26 +0000 (20:59 +0100)
src/App/Router.php
src/BaseModule.php
src/Factory/Api/Mastodon/Error.php
src/Module/BaseApi.php
src/Module/Special/HTTPException.php

index 0640e589d4eb0b2cbc60d50272a676dc551d56ce..2984a8acabe6aa3f42ddcd7d00c04dacd45ed868 100644 (file)
@@ -74,11 +74,6 @@ class Router
        /** @var RouteCollector */
        protected $routeCollector;
 
-       /**
-        * @var string The HTTP method
-        */
-       private $httpMethod;
-
        /**
         * @var array Module parameters
         */
@@ -139,10 +134,6 @@ class Router
                $this->logger = $logger;
                $this->dice_profiler_threshold = $config->get('system', 'dice_profiler_threshold', 0);
 
-               $httpMethod = $this->server['REQUEST_METHOD'] ?? self::GET;
-
-               $this->httpMethod = in_array($httpMethod, self::ALLOWED_METHODS) ? $httpMethod : self::GET;
-
                $this->routeCollector = isset($routeCollector) ?
                        $routeCollector :
                        new RouteCollector(new Std(), new GroupCountBased());
@@ -271,12 +262,12 @@ class Router
 
                $this->parameters = [];
 
-               $routeInfo  = $dispatcher->dispatch($this->httpMethod, $cmd);
+               $routeInfo  = $dispatcher->dispatch($this->args->getMethod(), $cmd);
                if ($routeInfo[0] === Dispatcher::FOUND) {
                        $moduleClass = $routeInfo[1];
                        $this->parameters = $routeInfo[2];
                } elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
-                       if ($this->httpMethod === static::OPTIONS) {
+                       if ($this->args->getMethod() === static::OPTIONS) {
                                // Default response for HTTP OPTIONS requests in case there is no special treatment
                                $moduleClass = Options::class;
                        } else {
index ae3b7214095a350d3ef18c2424b4b6afd3702157..bd096d94a45e29b9a373dd196011ee60fd8f8a02 100644 (file)
@@ -223,7 +223,7 @@ abstract class BaseModule implements ICanHandleRequests
 
                $this->profiler->set(microtime(true) - $timestamp, 'init');
 
-               switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
+               switch ($this->args->getMethod() ?? Router::GET) {
                        case Router::DELETE:
                                $this->delete($request);
                                break;
index 0d9d40a6030b22c10bc5790c9cb18d1d29ffeaf9..0f08ee90b321cdb8f5c08e2fa5a62741b7f85b28 100644 (file)
@@ -47,7 +47,7 @@ class Error extends BaseFactory
 
        private function logError(int $errorno, string $error)
        {
-               $this->logger->info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $this->server['REQUEST_METHOD'] ?? '', 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
+               $this->logger->info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
        }
 
        public function RecordNotFound()
index 181a518356c007e7b58863c733e3b269241a001e..b6824140db632ab8b73afbff30f0042baf6af2ea 100644 (file)
@@ -82,7 +82,7 @@ class BaseApi extends BaseModule
        public function run(array $request = [], bool $scopecheck = true): ResponseInterface
        {
                if ($scopecheck) {
-                       switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
+                       switch ($this->args->getMethod()) {
                                case Router::DELETE:
                                case Router::PATCH:
                                case Router::POST:
index 34bb67538555dd37e8103d59ba9a76263924c528..95448606e5020fd2142cab89082de4f6a47e13ff 100644 (file)
@@ -89,7 +89,7 @@ class HTTPException
                header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->getDescription());
 
                if ($e->getCode() >= 400) {
-                       Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->getDescription(), 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
+                       Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->getDescription(), 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
                }
 
                $tpl = Renderer::getMarkupTemplate('exception.tpl');