‪TYPO3CMS  10.4
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;
27 
38 class ‪RequestHandler implements RequestHandlerInterface
39 {
43  protected ‪$dispatcher;
44 
49  {
50  $this->dispatcher = ‪$dispatcher;
51  }
52 
62  protected function ‪resetGlobalsToCurrentRequest(ServerRequestInterface $request)
63  {
64  if ($request->getQueryParams() !== $_GET) {
65  $queryParams = $request->getQueryParams();
66  $_GET = $queryParams;
67  ‪$GLOBALS['HTTP_GET_VARS'] = $_GET;
68  }
69  if ($request->getMethod() === 'POST') {
70  $parsedBody = $request->getParsedBody();
71  if (is_array($parsedBody) && $parsedBody !== $_POST) {
72  $_POST = $parsedBody;
73  ‪$GLOBALS['HTTP_POST_VARS'] = $_POST;
74  }
75  }
76  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
77  }
78 
87  public function ‪handle(ServerRequestInterface $request): ResponseInterface
88  {
89  // safety net to have the fully-added request object globally available as long as
90  // there are Core classes that need the Request object but do not get it handed in
91  $this->‪resetGlobalsToCurrentRequest($request);
92  try {
93  // Check if the router has the available route and dispatch.
94  return $this->dispatcher->dispatch($request);
95  } catch (‪InvalidRequestTokenException $e) {
96  // When token was invalid redirect to login
97  $loginPage = GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute('login');
98  return new ‪RedirectResponse((string)$loginPage);
99  }
100  }
101 }
‪TYPO3\CMS\Backend\Http\RouteDispatcher
Definition: RouteDispatcher.php:36
‪TYPO3\CMS\Backend\Routing\Exception\InvalidRequestTokenException
Definition: InvalidRequestTokenException.php:24
‪TYPO3\CMS\Backend\Http\RequestHandler\resetGlobalsToCurrentRequest
‪resetGlobalsToCurrentRequest(ServerRequestInterface $request)
Definition: RequestHandler.php:61
‪TYPO3\CMS\Backend\Http
Definition: Application.php:18
‪TYPO3\CMS\Backend\Http\RequestHandler\$dispatcher
‪RouteDispatcher $dispatcher
Definition: RequestHandler.php:42
‪TYPO3\CMS\Backend\Http\RequestHandler\handle
‪ResponseInterface handle(ServerRequestInterface $request)
Definition: RequestHandler.php:86
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Http\RequestHandler
Definition: RequestHandler.php:39
‪TYPO3\CMS\Backend\Http\RequestHandler\__construct
‪__construct(RouteDispatcher $dispatcher)
Definition: RequestHandler.php:47
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46