‪TYPO3CMS  11.5
RequestHandler.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\RequestHandlerInterface;
31 
42 class ‪RequestHandler implements RequestHandlerInterface
43 {
45 
47 
49 
53  public function ‪__construct(
57  ) {
58  $this->dispatcher = ‪$dispatcher;
59  $this->uriBuilder = ‪$uriBuilder;
60  $this->listenerProvider = ‪$listenerProvider;
61  }
62 
72  protected function ‪resetGlobalsToCurrentRequest(ServerRequestInterface $request)
73  {
74  if ($request->getQueryParams() !== $_GET) {
75  $queryParams = $request->getQueryParams();
76  $_GET = $queryParams;
77  ‪$GLOBALS['HTTP_GET_VARS'] = $_GET;
78  }
79  if ($request->getMethod() === 'POST') {
80  $parsedBody = $request->getParsedBody();
81  if (is_array($parsedBody) && $parsedBody !== $_POST) {
82  $_POST = $parsedBody;
83  ‪$GLOBALS['HTTP_POST_VARS'] = $_POST;
84  }
85  }
86  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
87  }
88 
97  public function ‪handle(ServerRequestInterface $request): ResponseInterface
98  {
99  // Make sure all FAL resources have absolute URL paths
100  $this->listenerProvider->addListener(
101  GeneratePublicUrlForResourceEvent::class,
102  PublicUrlPrefixer::class,
103  'prefixWithSitePath'
104  );
105  // safety net to have the fully-added request object globally available as long as
106  // there are Core classes that need the Request object but do not get it handed in
107  $this->‪resetGlobalsToCurrentRequest($request);
108  try {
109  // Check if the router has the available route and dispatch.
110  return $this->dispatcher->dispatch($request);
111  } catch (‪MissingRequestTokenException $e) {
112  // When token was missing, then redirect to login, but keep the current route as redirect after login
113  $loginUrl = $this->uriBuilder->buildUriWithRedirect(
114  'login',
115  [],
116  ‪RouteRedirect::createFromRoute($request->getAttribute('route'), $request->getQueryParams())
117  );
118  return new ‪RedirectResponse($loginUrl);
119  } catch (‪InvalidRequestTokenException $e) {
120  // When token was invalid, then redirect to login
121  $loginForm = $this->uriBuilder->buildUriFromRoute('login');
122  return new ‪RedirectResponse($loginForm);
123  }
124  }
125 }
‪TYPO3\CMS\Backend\Http\RouteDispatcher
Definition: RouteDispatcher.php:41
‪TYPO3\CMS\Backend\Routing\Exception\InvalidRequestTokenException
Definition: InvalidRequestTokenException.php:23
‪TYPO3\CMS\Backend\Http\RequestHandler\resetGlobalsToCurrentRequest
‪resetGlobalsToCurrentRequest(ServerRequestInterface $request)
Definition: RequestHandler.php:72
‪TYPO3\CMS\Backend\Http\RequestHandler\$uriBuilder
‪UriBuilder $uriBuilder
Definition: RequestHandler.php:46
‪TYPO3\CMS\Backend\Http
Definition: Application.php:18
‪TYPO3\CMS\Backend\Http\RequestHandler\$dispatcher
‪RouteDispatcher $dispatcher
Definition: RequestHandler.php:44
‪TYPO3\CMS\Backend\Resource\PublicUrlPrefixer
Definition: PublicUrlPrefixer.php:26
‪TYPO3\CMS\Backend\Http\RequestHandler\$listenerProvider
‪ListenerProvider $listenerProvider
Definition: RequestHandler.php:48
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent
Definition: GeneratePublicUrlForResourceEvent.php:31
‪TYPO3\CMS\Backend\Http\RequestHandler\handle
‪ResponseInterface handle(ServerRequestInterface $request)
Definition: RequestHandler.php:97
‪TYPO3\CMS\Backend\Routing\RouteRedirect
Definition: RouteRedirect.php:30
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Backend\Http\RequestHandler
Definition: RequestHandler.php:43
‪TYPO3\CMS\Backend\Routing\Exception\MissingRequestTokenException
Definition: MissingRequestTokenException.php:23
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Routing\RouteRedirect\createFromRoute
‪static createFromRoute(Route $route, array $parameters)
Definition: RouteRedirect.php:53
‪TYPO3\CMS\Backend\Http\RequestHandler\__construct
‪__construct(RouteDispatcher $dispatcher, UriBuilder $uriBuilder, ListenerProvider $listenerProvider)
Definition: RequestHandler.php:53
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30