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