‪TYPO3CMS  ‪main
PageResolver.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;
31 
40 class ‪PageResolver implements MiddlewareInterface
41 {
45  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
46  {
47  $site = $request->getAttribute('site', null);
48 
49  if (!$site instanceof ‪Site) {
50  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
51  $request,
52  'No site configuration found.',
54  );
55  }
56 
58  $previousResult = $request->getAttribute('routing', null);
59  if (!$previousResult) {
60  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
61  $request,
62  'The requested page does not exist',
64  );
65  }
66 
67  // Check for the route arguments or Query Parameter ID
68  try {
70  $pageArguments = $site->getRouter()->matchRequest($request, $previousResult);
71  $request = $request->withAttribute('routing', $pageArguments);
72  } catch (‪RouteNotFoundException $e) {
73  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
74  $request,
75  'The requested page does not exist',
77  );
78  }
79 
80  if (!$pageArguments->getPageId()) {
81  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
82  $request,
83  'The requested page does not exist',
85  );
86  }
87 
88  // stop in case arguments are dirty (=defined twice in route and GET query parameters)
89  if ($pageArguments->areDirty()) {
90  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
91  $request,
92  'The requested URL is not distinct',
94  );
95  }
96 
97  // merge the PageArguments with the request query parameters
98  $queryParams = array_replace_recursive($request->getQueryParams(), $pageArguments->getArguments());
99  $request = $request->withQueryParams($queryParams);
100 
101  return $handler->handle($request);
102  }
103 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:26
‪TYPO3\CMS\Core\Routing\RouteNotFoundException
Definition: RouteNotFoundException.php:25
‪TYPO3\CMS\Frontend\Middleware\PageResolver
Definition: PageResolver.php:41
‪TYPO3\CMS\Frontend\Controller\ErrorController
Definition: ErrorController.php:38
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:18
‪TYPO3\CMS\Core\Routing\SiteRouteResult
Definition: SiteRouteResult.php:30
‪TYPO3\CMS\Frontend\Page\PageAccessFailureReasons\PAGE_NOT_FOUND
‪const PAGE_NOT_FOUND
Definition: PageAccessFailureReasons.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Frontend\Middleware\PageResolver\process
‪process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: PageResolver.php:45
‪TYPO3\CMS\Frontend\Page\PageAccessFailureReasons
Definition: PageAccessFailureReasons.php:25