2 declare(strict_types
= 1);
3 namespace TYPO3\CMS\Frontend\Middleware
;
6 * This file is part of the TYPO3 CMS project.
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.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use Psr\Http\Message\ResponseInterface
;
19 use Psr\Http\Message\ServerRequestInterface
;
20 use Psr\Http\Server\MiddlewareInterface
;
21 use Psr\Http\Server\RequestHandlerInterface
;
22 use TYPO3\CMS\Core\Exception
;
23 use TYPO3\CMS\Core\Http\Dispatcher
;
24 use TYPO3\CMS\Core\Http\NullResponse
;
25 use TYPO3\CMS\Core\Http\Response
;
26 use TYPO3\CMS\Core\Utility\GeneralUtility
;
29 * Lightweight alternative to regular frontend requests; used when $_GET[eID] is set.
30 * In the future, logic from the EidUtility will be moved to this class, however in most cases
31 * a custom PSR-15 middleware will be better suited for whatever job the eID functionality does currently.
35 class EidHandler
implements MiddlewareInterface
38 * Dispatches the request to the corresponding eID class or eID script
40 * @param ServerRequestInterface $request
41 * @param RequestHandlerInterface $handler
42 * @return ResponseInterface
45 public function process(ServerRequestInterface
$request, RequestHandlerInterface
$handler): ResponseInterface
47 $eID = $request->getParsedBody()['eID'] ??
$request->getQueryParams()['eID'] ??
null;
50 return $handler->handle($request);
53 // Remove any output produced until now
56 if (empty($eID) ||
!isset($GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID])) {
57 return (new Response())->withStatus(404, 'eID not registered');
60 $configuration = $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID];
62 // Simple check to make sure that it's not an absolute file (to use the fallback)
63 if (strpos($configuration, '::') !== false ||
is_callable($configuration)) {
64 $dispatcher = GeneralUtility
::makeInstance(Dispatcher
::class);
65 $request = $request->withAttribute('target', $configuration);
66 return $dispatcher->dispatch($request) ??
new NullResponse();
69 'eID "' . $eID . '" is registered with a script to a file. This behaviour will be removed in TYPO3 v10.0.'
70 . ' Register eID with a class::method syntax like "\MyVendor\MyExtension\Controller\MyEidController::myMethod" instead.',
73 $scriptPath = GeneralUtility
::getFileAbsFileName($configuration);
74 if ($scriptPath === '') {
75 throw new Exception('Registered eID has invalid script path.', 1518042216);
78 return new NullResponse();