[TASK] gitlab-ci nightly slack notification
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Middleware / EidHandler.php
1 <?php
2
3 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 namespace TYPO3\CMS\Frontend\Middleware;
19
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\MiddlewareInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
24 use TYPO3\CMS\Core\Exception;
25 use TYPO3\CMS\Core\Http\DispatcherInterface;
26 use TYPO3\CMS\Core\Http\NullResponse;
27 use TYPO3\CMS\Core\Http\Response;
28
29 /**
30 * Lightweight alternative to regular frontend requests; used when $_GET[eID] is set.
31 * In the future, logic from the EidUtility will be moved to this class, however in most cases
32 * a custom PSR-15 middleware will be better suited for whatever job the eID functionality does currently.
33 *
34 * @internal
35 */
36 class EidHandler implements MiddlewareInterface
37 {
38 /**
39 * @var DispatcherInterface
40 */
41 protected $dispatcher;
42
43 /**
44 * @param DispatcherInterface $dispatcher
45 */
46 public function __construct(DispatcherInterface $dispatcher)
47 {
48 $this->dispatcher = $dispatcher;
49 }
50
51 /**
52 * Dispatches the request to the corresponding eID class or eID script
53 *
54 * @param ServerRequestInterface $request
55 * @param RequestHandlerInterface $handler
56 * @return ResponseInterface
57 * @throws Exception
58 */
59 public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
60 {
61 $eID = $request->getParsedBody()['eID'] ?? $request->getQueryParams()['eID'] ?? null;
62
63 if ($eID === null) {
64 return $handler->handle($request);
65 }
66
67 // Remove any output produced until now
68 ob_clean();
69
70 $target = $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$eID] ?? null;
71 if (empty($target)) {
72 return (new Response())->withStatus(404, 'eID not registered');
73 }
74
75 $request = $request->withAttribute('target', $target);
76 return $this->dispatcher->dispatch($request) ?? new NullResponse();
77 }
78 }