[!!!][TASK] Remove constant TYPO3_PROCEED_IF_NO_USER
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Entry point for the TYPO3 Backend (HTTP requests)
22 */
23 class Application implements ApplicationInterface
24 {
25 /**
26 * @var Bootstrap
27 */
28 protected $bootstrap;
29
30 /**
31 * @var string
32 */
33 protected $entryPointPath = 'typo3/';
34
35 /**
36 * @var \Psr\Http\Message\ServerRequestInterface
37 */
38 protected $request;
39
40 /**
41 * All available request handlers that can handle backend requests (non-CLI)
42 * @var array
43 */
44 protected $availableRequestHandlers = array(
45 \TYPO3\CMS\Backend\Http\RequestHandler::class,
46 \TYPO3\CMS\Backend\Http\BackendModuleRequestHandler::class,
47 \TYPO3\CMS\Backend\Http\AjaxRequestHandler::class
48 );
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 ->baseSetup($this->entryPointPath);
62
63 // can be done here after the base setup is done
64 $this->defineAdditionalEntryPointRelatedConstants();
65
66 // Redirect to install tool if base configuration is not found
67 if (!$this->bootstrap->checkIfEssentialConfigurationExists()) {
68 $this->bootstrap->redirectToInstallTool($this->entryPointPath);
69 }
70
71 foreach ($this->availableRequestHandlers as $requestHandler) {
72 $this->bootstrap->registerRequestHandlerImplementation($requestHandler);
73 }
74
75 $this->bootstrap->configure();
76 }
77
78 /**
79 * Set up the application and shut it down afterwards
80 *
81 * @param callable $execute
82 * @return void
83 */
84 public function run(callable $execute = null)
85 {
86 $this->request = \TYPO3\CMS\Core\Http\ServerRequestFactory::fromGlobals();
87 // see below when this option is set and Bootstrap::defineTypo3RequestTypes() for more details
88 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
89 $this->request = $this->request->withAttribute('isAjaxRequest', true);
90 } elseif (isset($this->request->getQueryParams()['M'])) {
91 $this->request = $this->request->withAttribute('isModuleRequest', true);
92 }
93
94 $this->bootstrap->handleRequest($this->request);
95
96 if ($execute !== null) {
97 call_user_func($execute);
98 }
99
100 $this->bootstrap->shutdown();
101 }
102
103 /**
104 * Define constants and variables
105 */
106 protected function defineLegacyConstants()
107 {
108 define('TYPO3_MODE', 'BE');
109 }
110
111 /**
112 * Define values that are based on the current script
113 */
114 protected function defineAdditionalEntryPointRelatedConstants()
115 {
116 // Activate "AJAX" handler when called with the GET variable ajaxID
117 if (!empty(GeneralUtility::_GET('ajaxID'))) {
118 $GLOBALS['TYPO3_AJAX'] = true;
119 }
120 }
121 }