[!!!][TASK] Migrate modules to regular backend routing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Http / Application.php
1 <?php
2 namespace TYPO3\CMS\Backend\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 use TYPO3\CMS\Core\Core\ApplicationInterface;
17 use TYPO3\CMS\Core\Core\Bootstrap;
18
19 /**
20 * Entry point for the TYPO3 Backend (HTTP requests)
21 */
22 class Application implements ApplicationInterface
23 {
24 /**
25 * @var Bootstrap
26 */
27 protected $bootstrap;
28
29 /**
30 * Number of subdirectories where the entry script is located, relative to PATH_site
31 * Usually this is equal to PATH_site = 0
32 * @var int
33 */
34 protected $entryPointLevel = 1;
35
36 /**
37 * All available request handlers that can handle backend requests (non-CLI)
38 * @var array
39 */
40 protected $availableRequestHandlers = [
41 \TYPO3\CMS\Backend\Http\RequestHandler::class,
42 \TYPO3\CMS\Backend\Http\AjaxRequestHandler::class
43 ];
44
45 /**
46 * Constructor setting up legacy constant and register available Request Handlers
47 *
48 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
49 */
50 public function __construct($classLoader)
51 {
52 $this->defineLegacyConstants();
53
54 $this->bootstrap = Bootstrap::getInstance()
55 ->initializeClassLoader($classLoader)
56 ->setRequestType(TYPO3_REQUESTTYPE_BE | (isset($_REQUEST['route']) && strpos($_REQUEST['route'], '/ajax/') === 0 ? TYPO3_REQUESTTYPE_AJAX : 0))
57 ->baseSetup($this->entryPointLevel);
58
59 // Redirect to install tool if base configuration is not found
60 if (!$this->bootstrap->checkIfEssentialConfigurationExists()) {
61 $this->bootstrap->redirectToInstallTool($this->entryPointLevel);
62 }
63
64 foreach ($this->availableRequestHandlers as $requestHandler) {
65 $this->bootstrap->registerRequestHandlerImplementation($requestHandler);
66 }
67
68 $this->bootstrap->configure();
69 }
70
71 /**
72 * Set up the application and shut it down afterwards
73 *
74 * @param callable $execute
75 */
76 public function run(callable $execute = null)
77 {
78 $this->bootstrap->handleRequest(\TYPO3\CMS\Core\Http\ServerRequestFactory::fromGlobals());
79
80 if ($execute !== null) {
81 call_user_func($execute);
82 }
83
84 $this->bootstrap->shutdown();
85 }
86
87 /**
88 * Define constants and variables
89 */
90 protected function defineLegacyConstants()
91 {
92 define('TYPO3_MODE', 'BE');
93 }
94 }