2 namespace TYPO3\CMS\Backend\Http
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use TYPO3\CMS\Core\Core\ApplicationInterface
;
17 use TYPO3\CMS\Core\Core\Bootstrap
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * Entry point for the TYPO3 Backend (HTTP requests)
23 class Application
implements ApplicationInterface
{
33 protected $entryPointPath = 'typo3/';
36 * @var \Psr\Http\Message\ServerRequestInterface
41 * All available request handlers that can handle backend requests (non-CLI)
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
51 * Constructor setting up legacy constant and register available Request Handlers
53 * @param \Composer\Autoload\ClassLoader|\Helhum\ClassAliasLoader\Composer\ClassAliasLoader $classLoader an instance of the class loader
55 public function __construct($classLoader) {
56 $this->defineLegacyConstants();
58 $this->bootstrap
= Bootstrap
::getInstance()
59 ->initializeClassLoader($classLoader)
60 ->baseSetup($this->entryPointPath
);
62 // can be done here after the base setup is done
63 $this->defineAdditionalEntryPointRelatedConstants();
65 // Redirect to install tool if base configuration is not found
66 if (!$this->bootstrap
->checkIfEssentialConfigurationExists()) {
67 $this->bootstrap
->redirectToInstallTool($this->entryPointPath
);
70 foreach ($this->availableRequestHandlers
as $requestHandler) {
71 $this->bootstrap
->registerRequestHandlerImplementation($requestHandler);
74 $this->request
= \TYPO3\CMS\Core\Http\ServerRequestFactory
::fromGlobals();
75 // see below when this option is set
76 if ($GLOBALS['TYPO3_AJAX']) {
77 $this->request
= $this->request
->withAttribute('isAjaxRequest', TRUE);
78 } elseif (isset($this->request
->getQueryParams()['M'])) {
79 $this->request
= $this->request
->withAttribute('isModuleRequest', TRUE);
82 $this->bootstrap
->configure();
86 * Set up the application and shut it down afterwards
88 * @param callable $execute
91 public function run(callable
$execute = NULL) {
92 $this->bootstrap
->handleRequest($this->request
);
94 if ($execute !== NULL) {
95 if ($execute instanceof \Closure
) {
96 $execute->bindTo($this);
98 call_user_func($execute);
101 $this->bootstrap
->shutdown();
105 * Define constants and variables
107 protected function defineLegacyConstants() {
108 define('TYPO3_MODE', 'BE');
112 * Define values that are based on the current script
114 protected function defineAdditionalEntryPointRelatedConstants() {
115 $currentScript = GeneralUtility
::getIndpEnv('SCRIPT_NAME');
117 // Activate "AJAX" handler when called with the GET variable ajaxID
118 if (!empty(GeneralUtility
::_GET('ajaxID'))) {
119 $GLOBALS['TYPO3_AJAX'] = TRUE;
120 // The following check is security relevant! DO NOT REMOVE!
121 } elseif (empty(GeneralUtility
::_GET('M')) && substr($currentScript, -16) === '/typo3/index.php') {
122 // Allow backend login to work, disallow module access without authenticated backend user
123 define('TYPO3_PROCEED_IF_NO_USER', 1);