‪TYPO3CMS  ‪main
BackendRouteInitialization.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\MiddlewareInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
32 
49 class ‪BackendRouteInitialization implements MiddlewareInterface
50 {
51  public function ‪__construct(
52  protected readonly ‪Router $router,
53  protected readonly ‪UriBuilder $uriBuilder,
54  protected readonly ‪RequestContextFactory $requestContextFactory,
55  ) {}
56 
60  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
61  {
62  // @todo Find another place for this call, since it's not related to this middleware anymore
64  $this->uriBuilder->setRequestContext($this->requestContextFactory->fromBackendRequest($request));
65 
66  try {
67  $routeResult = $this->router->matchResult($request);
68  $request = $request->withAttribute('routing', $routeResult);
69  $request = $request->withAttribute('route', $routeResult->getRoute());
70  } catch (‪MethodNotAllowedException $e) {
71  return new ‪Response(null, 405);
72  } catch (‪ResourceNotFoundException $e) {
73  // Route not found in system
74  $uri = $this->uriBuilder->buildUriFromRoute('login');
75  return new ‪RedirectResponse($uri);
76  }
77 
78  return $handler->handle($request);
79  }
80 }
‪TYPO3\CMS\Backend\Middleware
Definition: AdditionalResponseHeaders.php:18
‪TYPO3\CMS\Backend\Routing\Exception\MethodNotAllowedException
Definition: MethodNotAllowedException.php:23
‪TYPO3\CMS\Backend\Middleware\BackendRouteInitialization\__construct
‪__construct(protected readonly Router $router, protected readonly UriBuilder $uriBuilder, protected readonly RequestContextFactory $requestContextFactory,)
Definition: BackendRouteInitialization.php:51
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:32
‪TYPO3\CMS\Backend\Middleware\BackendRouteInitialization
Definition: BackendRouteInitialization.php:50
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:30
‪TYPO3\CMS\Backend\Routing\Exception\ResourceNotFoundException
Definition: ResourceNotFoundException.php:23
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:62
‪TYPO3\CMS\Backend\Middleware\BackendRouteInitialization\process
‪process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: BackendRouteInitialization.php:60
‪TYPO3\CMS\Core\Core\Bootstrap\loadExtTables
‪static loadExtTables(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:495
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:40
‪TYPO3\CMS\Core\Routing\RequestContextFactory
Definition: RequestContextFactory.php:30