[TASK] Clean up Backend Controller
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Http / Application.php
1 <?php
2 namespace TYPO3\CMS\Install\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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use Psr\Http\Server\RequestHandlerInterface;
20 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
21 use TYPO3\CMS\Core\Context\Context;
22 use TYPO3\CMS\Core\Context\DateTimeAspect;
23 use TYPO3\CMS\Core\Context\UserAspect;
24 use TYPO3\CMS\Core\Context\VisibilityAspect;
25 use TYPO3\CMS\Core\Context\WorkspaceAspect;
26 use TYPO3\CMS\Core\Http\AbstractApplication;
27 use TYPO3\CMS\Core\Http\MiddlewareDispatcher;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29 use TYPO3\CMS\Install\Middleware\Installer;
30 use TYPO3\CMS\Install\Middleware\Maintenance;
31
32 /**
33 * Entry point for the TYPO3 Install Tool
34 * @internal This class is only meant to be used within EXT:install and is not part of the TYPO3 Core API.
35 */
36 class Application extends AbstractApplication
37 {
38 /**
39 * @var string
40 */
41 protected $requestHandler = NotFoundRequestHandler::class;
42
43 /**
44 * @var ConfigurationManager
45 */
46 protected $configurationManager;
47
48 /**
49 * @param ConfigurationManager $configurationManager
50 */
51 public function __construct(ConfigurationManager $configurationManager)
52 {
53 $this->configurationManager = $configurationManager;
54 }
55
56 /**
57 * @param RequestHandlerInterface $requestHandler
58 * @return MiddlewareDispatcher
59 */
60 protected function createMiddlewareDispatcher(RequestHandlerInterface $requestHandler): MiddlewareDispatcher
61 {
62 $dispatcher = new MiddlewareDispatcher($requestHandler);
63
64 // Stack of middlewares, executed LIFO
65 $dispatcher->lazy(Installer::class);
66 $dispatcher->add(GeneralUtility::makeInstance(Maintenance::class, $this->configurationManager));
67
68 return $dispatcher;
69 }
70
71 /**
72 * @param ServerRequestInterface $request
73 * @return ResponseInterface
74 */
75 protected function handle(ServerRequestInterface $request): ResponseInterface
76 {
77 $this->initializeContext();
78 return parent::handle($request);
79 }
80
81 /**
82 * Initializes the Context used for accessing data and finding out the current state of the application
83 * Will be moved to a DI-like concept once introduced, for now, this is a singleton
84 */
85 protected function initializeContext()
86 {
87 GeneralUtility::makeInstance(Context::class, [
88 'date' => new DateTimeAspect(new \DateTimeImmutable('@' . $GLOBALS['EXEC_TIME'])),
89 'visibility' => new VisibilityAspect(true, true, true),
90 'workspace' => new WorkspaceAspect(0),
91 'backend.user' => new UserAspect(),
92 ]);
93 }
94 }