‪TYPO3CMS  9.5
RequestHandler.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
20 use Psr\Http\Server\RequestHandlerInterface as PsrRequestHandlerInterface;
26 
37 class ‪RequestHandler implements ‪RequestHandlerInterface, PsrRequestHandlerInterface
38 {
45  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
46  {
47  return $this->‪handle($request);
48  }
49 
58  public function ‪handle(ServerRequestInterface $request): ResponseInterface
59  {
60  // Use a custom pre-created response for AJAX calls
61  // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0: No prepared $response to RouteDispatcher any longer
62  if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
63  $response = new ‪Response('php://temp', 200, [
64  'Content-Type' => 'application/json; charset=utf-8',
65  'X-JSON' => 'true'
66  ]);
67  } else {
68  $response = new ‪Response();
69  }
70  try {
71  // Check if the router has the available route and dispatch.
72  $dispatcher = GeneralUtility::makeInstance(RouteDispatcher::class);
73  return $dispatcher->dispatch($request, $response);
74  } catch (‪InvalidRequestTokenException $e) {
75  // When token was invalid redirect to login
76  $url = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
77  return new ‪RedirectResponse($url);
78  }
79  }
80 
87  public function ‪canHandleRequest(ServerRequestInterface $request): bool
88  {
89  return (bool)(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE);
90  }
91 
98  public function ‪getPriority(): int
99  {
100  return 50;
101  }
102 }
‪TYPO3\CMS\Backend\Http\RequestHandler\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: RequestHandler.php:45
‪TYPO3\CMS\Backend\Routing\Exception\InvalidRequestTokenException
Definition: InvalidRequestTokenException.php:21
‪TYPO3\CMS\Backend\Http
Definition: AjaxRequestHandler.php:3
‪TYPO3\CMS\Backend\Http\RequestHandler\canHandleRequest
‪bool canHandleRequest(ServerRequestInterface $request)
Definition: RequestHandler.php:87
‪TYPO3\CMS\Core\Http\RequestHandlerInterface
Definition: RequestHandlerInterface.php:28
‪TYPO3\CMS\Backend\Http\RequestHandler\handle
‪ResponseInterface handle(ServerRequestInterface $request)
Definition: RequestHandler.php:58
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:28
‪TYPO3\CMS\Backend\Http\RequestHandler
Definition: RequestHandler.php:38
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Http\RequestHandler\getPriority
‪int getPriority()
Definition: RequestHandler.php:98