[BUGFIX] Hand over new parameters to DataHandler clones
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Http / Application.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Frontend\Http;
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\RequestHandlerInterface;
21 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
22 use TYPO3\CMS\Core\Context\Context;
23 use TYPO3\CMS\Core\Context\DateTimeAspect;
24 use TYPO3\CMS\Core\Context\UserAspect;
25 use TYPO3\CMS\Core\Context\VisibilityAspect;
26 use TYPO3\CMS\Core\Context\WorkspaceAspect;
27 use TYPO3\CMS\Core\Core\Environment;
28 use TYPO3\CMS\Core\Http\AbstractApplication;
29 use TYPO3\CMS\Core\Http\RedirectResponse;
30
31 /**
32 * Entry point for the TYPO3 Frontend
33 */
34 class Application extends AbstractApplication
35 {
36 /**
37 * @var ConfigurationManager
38 */
39 protected $configurationManager;
40
41 /**
42 * @var Context
43 */
44 protected $context;
45
46 public function __construct(
47 RequestHandlerInterface $requestHandler,
48 ConfigurationManager $configurationManager,
49 Context $context
50 ) {
51 $this->requestHandler = $requestHandler;
52 $this->configurationManager = $configurationManager;
53 $this->context = $context;
54 }
55
56 protected function handle(ServerRequestInterface $request): ResponseInterface
57 {
58 if (!$this->checkIfEssentialConfigurationExists()) {
59 return $this->installToolRedirect();
60 }
61 $this->initializeContext();
62 return parent::handle($request);
63 }
64
65 /**
66 * Check if LocalConfiguration.php and PackageStates.php exist
67 *
68 * @return bool TRUE when the essential configuration is available, otherwise FALSE
69 */
70 protected function checkIfEssentialConfigurationExists(): bool
71 {
72 return file_exists($this->configurationManager->getLocalConfigurationFileLocation())
73 && file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php');
74 }
75
76 /**
77 * Create a PSR-7 Response that redirects to the install tool
78 *
79 * @return ResponseInterface
80 */
81 protected function installToolRedirect(): ResponseInterface
82 {
83 $path = TYPO3_mainDir . 'install.php';
84 return new RedirectResponse($path, 302);
85 }
86
87 /**
88 * Initializes the Context used for accessing data and finding out the current state of the application
89 */
90 protected function initializeContext(): void
91 {
92 $this->context->setAspect('date', new DateTimeAspect(new \DateTimeImmutable('@' . $GLOBALS['EXEC_TIME'])));
93 $this->context->setAspect('visibility', new VisibilityAspect());
94 $this->context->setAspect('workspace', new WorkspaceAspect(0));
95 $this->context->setAspect('backend.user', new UserAspect(null));
96 $this->context->setAspect('frontend.user', new UserAspect(null, [0, -1]));
97 }
98 }