Create the RouteParsing middleware

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-08-15 17:25:13 -03:00
parent 6d8023afb1
commit 4474cdb65c
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
4 changed files with 30 additions and 6 deletions

View File

@ -27,6 +27,7 @@ use PhpMyAdmin\Middleware\ErrorHandling;
use PhpMyAdmin\Middleware\OutputBuffering;
use PhpMyAdmin\Middleware\PhpExtensionsChecking;
use PhpMyAdmin\Middleware\PhpSettingsConfiguration;
use PhpMyAdmin\Middleware\RouteParsing;
use PhpMyAdmin\Middleware\ServerConfigurationChecking;
use PhpMyAdmin\Middleware\UriSchemeUpdating;
use PhpMyAdmin\Plugins\AuthenticationPlugin;
@ -86,6 +87,7 @@ class Application
$requestHandler->add(new PhpExtensionsChecking($this, $this->template, $this->responseFactory));
$requestHandler->add(new ServerConfigurationChecking($this->template, $this->responseFactory));
$requestHandler->add(new PhpSettingsConfiguration());
$requestHandler->add(new RouteParsing());
$requestHandler->add(new ConfigLoading($this->config, $this->template, $this->responseFactory));
$requestHandler->add(new UriSchemeUpdating($this->config));
@ -111,8 +113,6 @@ class Application
$isSetupPage = (bool) $request->getAttribute('isSetupPage');
$route = $request->getRoute();
Routing::$route = $route;
$isMinimumCommon = $isSetupPage || $route === '/import-status' || $route === '/url' || $route === '/messages';
if ($route !== '/messages') {

View File

@ -274,7 +274,7 @@ class ServerRequest implements ServerRequestInterface
/** @psalm-return non-empty-string */
public function getRoute(): string
{
$route = $this->getQueryParam('route') ?? $this->getParsedBodyParam('route');
$route = $this->getAttribute('route') ?? $this->getQueryParam('route') ?? $this->getParsedBodyParam('route');
if (! is_string($route) || $route === '') {
return '/';
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Middleware;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Routing\Routing;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function assert;
final class RouteParsing implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
assert($request instanceof ServerRequest);
$route = $request->getRoute();
/** @psalm-suppress DeprecatedProperty */
Routing::$route = $route;
return $handler->handle($request->withAttribute('route', $route));
}
}

View File

@ -17,9 +17,6 @@
</MixedAssignment>
</file>
<file src="libraries/classes/Application.php">
<DeprecatedProperty>
<code>Routing::$route</code>
</DeprecatedProperty>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['back']]]></code>
</InvalidArrayOffset>