[!!!][TASK] Remove request type specific code in Bootstrap
[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 TYPO3\CMS\Core\Core\Bootstrap;
20 use TYPO3\CMS\Core\Http\AbstractApplication;
21 use TYPO3\CMS\Core\Http\RedirectResponse;
22
23 /**
24 * Entry point for the TYPO3 Backend (HTTP requests)
25 */
26 class Application extends AbstractApplication
27 {
28 /**
29 * @var string
30 */
31 protected $requestHandler = RequestHandler::class;
32
33 /**
34 * @var string
35 */
36 protected $middlewareStack = 'backend';
37
38 /**
39 * @var Bootstrap
40 */
41 protected $bootstrap;
42
43 /**
44 * Number of subdirectories where the entry script is located, relative to PATH_site
45 * Usually this is equal to PATH_site = 0
46 * @var int
47 */
48 protected $entryPointLevel = 1;
49
50 /**
51 * Constructor setting up legacy constant and register available Request Handlers
52 *
53 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
54 */
55 public function __construct($classLoader)
56 {
57 $this->defineLegacyConstants();
58
59 $this->bootstrap = Bootstrap::getInstance()
60 ->initializeClassLoader($classLoader)
61 ->setRequestType(TYPO3_REQUESTTYPE_BE | (isset($_REQUEST['route']) && strpos($_REQUEST['route'], '/ajax/') === 0 ? TYPO3_REQUESTTYPE_AJAX : 0))
62 ->baseSetup($this->entryPointLevel);
63
64 // Redirect to install tool if base configuration is not found
65 if (!$this->bootstrap->checkIfEssentialConfigurationExists()) {
66 $this->sendResponse($this->installToolRedirect());
67 exit;
68 }
69
70 $this->bootstrap->configure();
71 }
72
73 /**
74 * Define constants and variables
75 */
76 protected function defineLegacyConstants()
77 {
78 define('TYPO3_MODE', 'BE');
79 }
80
81 /**
82 * Create a PSR-7 Response that redirects to the install tool
83 *
84 * @return ResponseInterface
85 */
86 protected function installToolRedirect(): ResponseInterface
87 {
88 $path = '../' . TYPO3_mainDir . 'install.php';
89 return new RedirectResponse($path, 302);
90 }
91 }