TYPO3  7.6
EidRequestHandler.php
Go to the documentation of this file.
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 
26 
32 {
37  protected $bootstrap;
38 
44  public function __construct(Bootstrap $bootstrap)
45  {
46  $this->bootstrap = $bootstrap;
47  }
48 
55  public function handleRequest(ServerRequestInterface $request)
56  {
57  // Timetracking started
58  $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
59  if (empty($configuredCookieName)) {
60  $configuredCookieName = 'be_typo_user';
61  }
62  if ($request->getCookieParams()[$configuredCookieName]) {
63  $GLOBALS['TT'] = new TimeTracker();
64  } else {
65  $GLOBALS['TT'] = new NullTimeTracker();
66  }
67 
68  $GLOBALS['TT']->start();
69 
70  // Hook to preprocess the current request
71  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
72  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
73  $hookParameters = array();
74  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
75  }
76  unset($hookFunction);
77  unset($hookParameters);
78  }
79 
80  // Remove any output produced until now
81  $this->bootstrap->endOutputBufferingAndCleanPreviousOutput();
82  return $this->dispatch($request);
83  }
84 
91  public function canHandleRequest(ServerRequestInterface $request)
92  {
93  return !empty($request->getQueryParams()['eID']) || !empty($request->getParsedBody()['eID']);
94  }
95 
102  public function getPriority()
103  {
104  return 80;
105  }
106 
114  protected function dispatch($request)
115  {
117  $response = GeneralUtility::makeInstance(Response::class);
118 
119  $eID = isset($request->getParsedBody()['eID'])
120  ? $request->getParsedBody()['eID']
121  : (isset($request->getQueryParams()['eID']) ? $request->getQueryParams()['eID'] : '');
122 
123  if (empty($eID) || !isset($GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID])) {
124  return $response->withStatus(404, 'eID not registered');
125  }
126 
127  $configuration = $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID];
128 
129  // Simple check to make sure that it's not an absolute file (to use the fallback)
130  if (strpos($configuration, '::') !== false || is_callable($configuration)) {
132  $dispatcher = GeneralUtility::makeInstance(Dispatcher::class);
133  $request = $request->withAttribute('target', $configuration);
134  return $dispatcher->dispatch($request, $response);
135  }
136 
137  $scriptPath = GeneralUtility::getFileAbsFileName($configuration);
138  if ($scriptPath === '') {
139  throw new Exception('Registered eID has invalid script path.', 1416391467);
140  }
141  include $scriptPath;
142  return null;
143  }
144 }