‪TYPO3CMS  ‪main
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 
50  public function ‪__construct(
54  ) {
55  $this->dispatcher = ‪$dispatcher;
56  $this->uriBuilder = ‪$uriBuilder;
57  $this->listenerProvider = ‪$listenerProvider;
58  }
59 
69  protected function ‪resetGlobalsToCurrentRequest(ServerRequestInterface $request)
70  {
71  if ($request->getQueryParams() !== $_GET) {
72  $queryParams = $request->getQueryParams();
73  $_GET = $queryParams;
74  ‪$GLOBALS['HTTP_GET_VARS'] = $_GET;
75  }
76  if ($request->getMethod() === 'POST') {
77  $parsedBody = $request->getParsedBody();
78  if (is_array($parsedBody) && $parsedBody !== $_POST) {
79  $_POST = $parsedBody;
80  ‪$GLOBALS['HTTP_POST_VARS'] = $_POST;
81  }
82  }
83  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
84  }
85 
91  public function ‪handle(ServerRequestInterface $request): ResponseInterface
92  {
93  // Make sure all FAL resources have absolute URL paths
94  $this->listenerProvider->addListener(
95  GeneratePublicUrlForResourceEvent::class,
96  PublicUrlPrefixer::class,
97  'prefixWithSitePath'
98  );
99  // safety net to have the fully-added request object globally available as long as
100  // there are Core classes that need the Request object but do not get it handed in
101  $this->‪resetGlobalsToCurrentRequest($request);
102  try {
103  // Check if the router has the available route and dispatch.
104  return $this->dispatcher->dispatch($request);
105  } catch (‪MissingRequestTokenException $e) {
106  // When token was missing, then redirect to login, but keep the current route as redirect after login
107  $loginUrl = $this->uriBuilder->buildUriWithRedirect(
108  'login',
109  [],
110  ‪RouteRedirect::createFromRoute($request->getAttribute('route'), $request->getQueryParams())
111  );
112  return new ‪RedirectResponse($loginUrl);
113  } catch (‪InvalidRequestTokenException $e) {
114  // When token was invalid, then redirect to login
115  $loginForm = $this->uriBuilder->buildUriFromRoute('login');
116  return new ‪RedirectResponse($loginForm);
117  }
118  }
119 }
‪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:69
‪TYPO3\CMS\Backend\Http\RequestHandler\$uriBuilder
‪UriBuilder $uriBuilder
Definition: RequestHandler.php:46
‪TYPO3\CMS\Backend\Http\RequestHandler\handle
‪handle(ServerRequestInterface $request)
Definition: RequestHandler.php:91
‪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\Routing\RouteRedirect
Definition: RouteRedirect.php:30
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪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:30
‪$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:50
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30