Use Args::getMethod() at various places

This commit is contained in:
Philipp Holzer 2022-01-02 22:25:50 +01:00
parent ee2a15d822
commit 4e67bfed8d
Signed by: nupplaPhil
GPG Key ID: 24A7501396EB5432
5 changed files with 6 additions and 15 deletions

View 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 {

View 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;

View 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()

View 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:

View 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');