‪TYPO3CMS  9.5
EidHandler.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\MiddlewareInterface;
21 use Psr\Http\Server\RequestHandlerInterface;
27 
35 class ‪EidHandler implements MiddlewareInterface
36 {
45  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
46  {
47  $eID = $request->getParsedBody()['eID'] ?? $request->getQueryParams()['eID'] ?? null;
48 
49  if ($eID === null) {
50  return $handler->handle($request);
51  }
52 
53  // Remove any output produced until now
54  ob_clean();
55 
57  $response = GeneralUtility::makeInstance(Response::class);
58 
59  if (empty($eID) || !isset(‪$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID])) {
60  return $response->withStatus(404, 'eID not registered');
61  }
62 
63  $configuration = ‪$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID];
64 
65  // Simple check to make sure that it's not an absolute file (to use the fallback)
66  if (strpos($configuration, '::') !== false || is_callable($configuration)) {
68  $dispatcher = GeneralUtility::makeInstance(Dispatcher::class);
69  $request = $request->withAttribute('target', $configuration);
70  return $dispatcher->dispatch($request, $response) ?? new ‪NullResponse();
71  }
72  trigger_error(
73  'eID "' . $eID . '" is registered with a script to a file. This behaviour will be removed in TYPO3 v10.0.'
74  . ' Register eID with a class::method syntax like "\MyVendor\MyExtension\Controller\MyEidController::myMethod" instead.',
75  E_USER_DEPRECATED
76  );
77  $scriptPath = GeneralUtility::getFileAbsFileName($configuration);
78  if ($scriptPath === '') {
79  throw new ‪Exception('Registered eID has invalid script path.', 1518042216);
80  }
81  include $scriptPath;
82  return new ‪NullResponse();
83  }
84 }
‪TYPO3\CMS\Core\Http\Dispatcher
Definition: Dispatcher.php:29
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Frontend\Middleware\EidHandler
Definition: EidHandler.php:36
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Http\NullResponse
Definition: NullResponse.php:24
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:28
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:4
‪TYPO3\CMS\Frontend\Middleware\EidHandler\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: EidHandler.php:45
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45