[TASK] Apply CGL compatibility (PSR-1 and PSR-2)
[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 * @var string
31 */
32 protected $entryPointPath = 'typo3/';
33
34 /**
35 * @var \Psr\Http\Message\ServerRequestInterface
36 */
37 protected $request;
38
39 /**
40 * All available request handlers that can handle backend requests (non-CLI)
41 * @var array
42 */
43 protected $availableRequestHandlers = array(
44 \TYPO3\CMS\Backend\Http\RequestHandler::class,
45 \TYPO3\CMS\Backend\Http\BackendModuleRequestHandler::class,
46 \TYPO3\CMS\Backend\Http\AjaxRequestHandler::class
47 );
48
49 /**
50 * Constructor setting up legacy constant and register available Request Handlers
51 *
52 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
53 */
54 public function __construct($classLoader)
55 {
56 $this->defineLegacyConstants();
57
58 $this->bootstrap = Bootstrap::getInstance()
59 ->initializeClassLoader($classLoader)
60 ->setRequestType(TYPO3_REQUESTTYPE_BE | (!empty($_GET['ajaxID']) ? TYPO3_REQUESTTYPE_AJAX : 0))
61 ->baseSetup($this->entryPointPath);
62
63 // Redirect to install tool if base configuration is not found
64 if (!$this->bootstrap->checkIfEssentialConfigurationExists()) {
65 $this->bootstrap->redirectToInstallTool($this->entryPointPath);
66 }
67
68 foreach ($this->availableRequestHandlers as $requestHandler) {
69 $this->bootstrap->registerRequestHandlerImplementation($requestHandler);
70 }
71
72 $this->bootstrap->configure();
73 }
74
75 /**
76 * Set up the application and shut it down afterwards
77 *
78 * @param callable $execute
79 * @return void
80 */
81 public function run(callable $execute = null)
82 {
83 $this->request = \TYPO3\CMS\Core\Http\ServerRequestFactory::fromGlobals();
84 // see below when this option is set and Bootstrap::defineTypo3RequestTypes() for more details
85 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
86 $this->request = $this->request->withAttribute('isAjaxRequest', true);
87 } elseif (isset($this->request->getQueryParams()['M'])) {
88 $this->request = $this->request->withAttribute('isModuleRequest', true);
89 }
90
91 $this->bootstrap->handleRequest($this->request);
92
93 if ($execute !== null) {
94 call_user_func($execute);
95 }
96
97 $this->bootstrap->shutdown();
98 }
99
100 /**
101 * Define constants and variables
102 */
103 protected function defineLegacyConstants()
104 {
105 define('TYPO3_MODE', 'BE');
106 }
107 }