diff --git a/src/App/Router.php b/src/App/Router.php index 0640e589d4..2984a8acab 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -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 { diff --git a/src/BaseModule.php b/src/BaseModule.php index ae3b721409..bd096d94a4 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -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; diff --git a/src/Factory/Api/Mastodon/Error.php b/src/Factory/Api/Mastodon/Error.php index 0d9d40a603..0f08ee90b3 100644 --- a/src/Factory/Api/Mastodon/Error.php +++ b/src/Factory/Api/Mastodon/Error.php @@ -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() diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 181a518356..b6824140db 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -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: diff --git a/src/Module/Special/HTTPException.php b/src/Module/Special/HTTPException.php index 34bb675385..95448606e5 100644 --- a/src/Module/Special/HTTPException.php +++ b/src/Module/Special/HTTPException.php @@ -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');