2 namespace TYPO3\CMS\Frontend\Http
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use Psr\Http\Message\ServerRequestInterface
;
18 use TYPO3\CMS\Core\Core\Bootstrap
;
19 use TYPO3\CMS\Core\Exception
;
20 use TYPO3\CMS\Core\Http\Dispatcher
;
21 use TYPO3\CMS\Core\Http\RequestHandlerInterface
;
22 use TYPO3\CMS\Core\Http\Response
;
23 use TYPO3\CMS\Core\TimeTracker\TimeTracker
;
24 use TYPO3\CMS\Core\Utility\GeneralUtility
;
27 * Lightweight alternative to the regular RequestHandler used when $_GET[eID] is set.
28 * In the future, logic from the EidUtility will be moved to this class.
30 class EidRequestHandler
implements RequestHandlerInterface
33 * Instance of the current TYPO3 bootstrap
39 * Constructor handing over the bootstrap and the original request
41 * @param Bootstrap $bootstrap
43 public function __construct(Bootstrap
$bootstrap)
45 $this->bootstrap
= $bootstrap;
49 * Handles a frontend request based on the _GP "eID" variable.
51 * @param ServerRequestInterface $request
52 * @return \Psr\Http\Message\ResponseInterface|null
54 public function handleRequest(ServerRequestInterface
$request)
56 // Starting time tracking
57 $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?
: 'be_typo_user';
59 /** @var TimeTracker $timeTracker */
60 $timeTracker = GeneralUtility
::makeInstance(TimeTracker
::class, ($request->getCookieParams()[$configuredCookieName] ?
true : false));
61 $timeTracker->start();
63 // Hook to preprocess the current request
64 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
65 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
67 GeneralUtility
::callUserFunction($hookFunction, $hookParameters, $hookParameters);
70 unset($hookParameters);
73 // Remove any output produced until now
74 $this->bootstrap
->endOutputBufferingAndCleanPreviousOutput();
75 return $this->dispatch($request);
79 * This request handler can handle any frontend request.
81 * @param ServerRequestInterface $request The request to process
82 * @return bool If the request is not an eID request, TRUE otherwise FALSE
84 public function canHandleRequest(ServerRequestInterface
$request)
86 return !empty($request->getQueryParams()['eID']) ||
!empty($request->getParsedBody()['eID']);
90 * Returns the priority - how eager the handler is to actually handle the
93 * @return int The priority of the request handler.
95 public function getPriority()
101 * Dispatches the request to the corresponding eID class or eID script
103 * @param ServerRequestInterface $request
104 * @return \Psr\Http\Message\ResponseInterface|null
107 protected function dispatch($request)
109 /** @var Response $response */
110 $response = GeneralUtility
::makeInstance(Response
::class);
112 $eID = isset($request->getParsedBody()['eID'])
113 ?
$request->getParsedBody()['eID']
114 : (isset($request->getQueryParams()['eID']) ?
$request->getQueryParams()['eID'] : '');
116 if (empty($eID) ||
!isset($GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID])) {
117 return $response->withStatus(404, 'eID not registered');
120 $configuration = $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID];
122 // Simple check to make sure that it's not an absolute file (to use the fallback)
123 if (strpos($configuration, '::') !== false ||
is_callable($configuration)) {
124 /** @var Dispatcher $dispatcher */
125 $dispatcher = GeneralUtility
::makeInstance(Dispatcher
::class);
126 $request = $request->withAttribute('target', $configuration);
127 return $dispatcher->dispatch($request, $response);
130 $scriptPath = GeneralUtility
::getFileAbsFileName($configuration);
131 if ($scriptPath === '') {
132 throw new Exception('Registered eID has invalid script path.', 1416391467);