[FEATURE] Introduce Request/Response based on PSR-7
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Http / EidRequestHandler.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Http;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Core\Bootstrap;
18 use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
19 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
20 use TYPO3\CMS\Frontend\Utility\EidUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Core\RequestHandlerInterface;
23 use Psr\Http\Message\ServerRequestInterface;
24
25 /**
26 * Lightweight alternative to the regular RequestHandler used when $_GET[eID] is set.
27 * In the future, logic from the EidUtility will be moved to this class.
28 */
29 class EidRequestHandler implements RequestHandlerInterface {
30
31 /**
32 * Instance of the current TYPO3 bootstrap
33 * @var Bootstrap
34 */
35 protected $bootstrap;
36
37 /**
38 * Constructor handing over the bootstrap and the original request
39 *
40 * @param Bootstrap $bootstrap
41 */
42 public function __construct(Bootstrap $bootstrap) {
43 $this->bootstrap = $bootstrap;
44 }
45
46 /**
47 * Handles a frontend request based on the _GP "eID" variable.
48 *
49 * @param ServerRequestInterface $request
50 * @return NULL|\Psr\Http\Message\ResponseInterface
51 */
52 public function handleRequest(ServerRequestInterface $request) {
53 $response = NULL;
54 // Timetracking started
55 $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
56 if (empty($configuredCookieName)) {
57 $configuredCookieName = 'be_typo_user';
58 }
59 if ($request->getCookieParams()[$configuredCookieName]) {
60 $GLOBALS['TT'] = new TimeTracker();
61 } else {
62 $GLOBALS['TT'] = new NullTimeTracker();
63 }
64
65 $GLOBALS['TT']->start();
66
67 // Hook to preprocess the current request
68 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
69 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
70 $hookParameters = array();
71 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
72 }
73 unset($hookFunction);
74 unset($hookParameters);
75 }
76
77 // Remove any output produced until now
78 $this->bootstrap->endOutputBufferingAndCleanPreviousOutput();
79 require EidUtility::getEidScriptPath();
80
81 return $response;
82 }
83
84 /**
85 * This request handler can handle any frontend request.
86 *
87 * @param ServerRequestInterface $request The request to process
88 * @return bool If the request is not an eID request, TRUE otherwise FALSE
89 */
90 public function canHandleRequest(ServerRequestInterface $request) {
91 return $request->getQueryParams()['eID'] || $request->getParsedBody()['eID'] ? TRUE : FALSE;
92 }
93
94 /**
95 * Returns the priority - how eager the handler is to actually handle the
96 * request.
97 *
98 * @return int The priority of the request handler.
99 */
100 public function getPriority() {
101 return 80;
102 }
103
104 }