[!!!][TASK] Remove non-route variants for BE calls
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Middleware / BackendRouteInitialization.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Middleware;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
20 use Psr\Http\Server\MiddlewareInterface;
21 use Psr\Http\Server\RequestHandlerInterface;
22 use TYPO3\CMS\Backend\Routing\Router;
23 use TYPO3\CMS\Core\Core\Bootstrap;
24
25 /**
26 * Initializes the Backend Router and also loads ext_tables.php from all extensions, as this is the place
27 * where all modules register their routes to the router afterwards.
28 *
29 * The route path is added to the request as attribute "routePath".
30 *
31 * @internal
32 */
33 class BackendRouteInitialization implements MiddlewareInterface
34 {
35 /**
36 * Resolve the &route (or &M) GET/POST parameter, and also the Router object.
37 *
38 * @param ServerRequestInterface $request
39 * @param RequestHandlerInterface $handler
40 * @return ResponseInterface
41 */
42 public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
43 {
44 // Allow the login page to be displayed if routing is not used and on index.php
45 $pathToRoute = $request->getQueryParams()['route'] ?? $request->getParsedBody()['route'] ?? '/login';
46
47 Bootstrap::initializeBackendRouter();
48 Bootstrap::loadExtTables();
49
50 // Add the route path to the request
51 $request = $request->withAttribute('routePath', $pathToRoute);
52
53 return $handler->handle($request);
54 }
55 }