Use Args::getMethod() at various places
This commit is contained in:
parent
ee2a15d822
commit
4e67bfed8d
|
@ -74,11 +74,6 @@ class Router
|
||||||
/** @var RouteCollector */
|
/** @var RouteCollector */
|
||||||
protected $routeCollector;
|
protected $routeCollector;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string The HTTP method
|
|
||||||
*/
|
|
||||||
private $httpMethod;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Module parameters
|
* @var array Module parameters
|
||||||
*/
|
*/
|
||||||
|
@ -139,10 +134,6 @@ class Router
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->dice_profiler_threshold = $config->get('system', 'dice_profiler_threshold', 0);
|
$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) ?
|
$this->routeCollector = isset($routeCollector) ?
|
||||||
$routeCollector :
|
$routeCollector :
|
||||||
new RouteCollector(new Std(), new GroupCountBased());
|
new RouteCollector(new Std(), new GroupCountBased());
|
||||||
|
@ -271,12 +262,12 @@ class Router
|
||||||
|
|
||||||
$this->parameters = [];
|
$this->parameters = [];
|
||||||
|
|
||||||
$routeInfo = $dispatcher->dispatch($this->httpMethod, $cmd);
|
$routeInfo = $dispatcher->dispatch($this->args->getMethod(), $cmd);
|
||||||
if ($routeInfo[0] === Dispatcher::FOUND) {
|
if ($routeInfo[0] === Dispatcher::FOUND) {
|
||||||
$moduleClass = $routeInfo[1];
|
$moduleClass = $routeInfo[1];
|
||||||
$this->parameters = $routeInfo[2];
|
$this->parameters = $routeInfo[2];
|
||||||
} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
|
} 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
|
// Default response for HTTP OPTIONS requests in case there is no special treatment
|
||||||
$moduleClass = Options::class;
|
$moduleClass = Options::class;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -223,7 +223,7 @@ abstract class BaseModule implements ICanHandleRequests
|
||||||
|
|
||||||
$this->profiler->set(microtime(true) - $timestamp, 'init');
|
$this->profiler->set(microtime(true) - $timestamp, 'init');
|
||||||
|
|
||||||
switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
|
switch ($this->args->getMethod() ?? Router::GET) {
|
||||||
case Router::DELETE:
|
case Router::DELETE:
|
||||||
$this->delete($request);
|
$this->delete($request);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Error extends BaseFactory
|
||||||
|
|
||||||
private function logError(int $errorno, string $error)
|
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()
|
public function RecordNotFound()
|
||||||
|
|
|
@ -82,7 +82,7 @@ class BaseApi extends BaseModule
|
||||||
public function run(array $request = [], bool $scopecheck = true): ResponseInterface
|
public function run(array $request = [], bool $scopecheck = true): ResponseInterface
|
||||||
{
|
{
|
||||||
if ($scopecheck) {
|
if ($scopecheck) {
|
||||||
switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
|
switch ($this->args->getMethod()) {
|
||||||
case Router::DELETE:
|
case Router::DELETE:
|
||||||
case Router::PATCH:
|
case Router::PATCH:
|
||||||
case Router::POST:
|
case Router::POST:
|
||||||
|
|
|
@ -89,7 +89,7 @@ class HTTPException
|
||||||
header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->getDescription());
|
header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->getDescription());
|
||||||
|
|
||||||
if ($e->getCode() >= 400) {
|
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');
|
$tpl = Renderer::getMarkupTemplate('exception.tpl');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user