[!!!][TASK] Drop "documentation" extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Http / Application.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\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 TYPO3\CMS\Core\Configuration\ConfigurationManager;
21 use TYPO3\CMS\Core\Http\AbstractApplication;
22 use TYPO3\CMS\Core\Http\RedirectResponse;
23
24 /**
25 * Entry point for the TYPO3 Backend (HTTP requests)
26 */
27 class Application extends AbstractApplication
28 {
29 /**
30 * @var string
31 */
32 protected $requestHandler = RequestHandler::class;
33
34 /**
35 * @var string
36 */
37 protected $middlewareStack = 'backend';
38
39 /**
40 * @var ConfigurationManager
41 */
42 protected $configurationManager;
43
44 /**
45 * @param ConfigurationManager $configurationManager
46 */
47 public function __construct(ConfigurationManager $configurationManager)
48 {
49 $this->configurationManager = $configurationManager;
50 }
51
52 /**
53 * @param ServerRequestInterface $request
54 * @return ResponseInterface
55 */
56 protected function handle(ServerRequestInterface $request): ResponseInterface
57 {
58 if (!$this->checkIfEssentialConfigurationExists()) {
59 return $this->installToolRedirect();
60 }
61 return parent::handle($request);
62 }
63
64 /**
65 * Check if LocalConfiguration.php and PackageStates.php exist
66 *
67 * @return bool TRUE when the essential configuration is available, otherwise FALSE
68 */
69 protected function checkIfEssentialConfigurationExists(): bool
70 {
71 return file_exists($this->configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
72 }
73
74 /**
75 * Create a PSR-7 Response that redirects to the install tool
76 *
77 * @return ResponseInterface
78 */
79 protected function installToolRedirect(): ResponseInterface
80 {
81 return new RedirectResponse('./install.php', 302);
82 }
83 }