TYPO3  7.6
typo3/sysext/backend/Classes/Http/Application.php
Go to the documentation of this file.
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  */
19 
24 {
28  protected $bootstrap;
29 
33  protected $entryPointPath = 'typo3/';
34 
38  protected $request;
39 
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 
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
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->request = \TYPO3\CMS\Core\Http\ServerRequestFactory::fromGlobals();
76  // see below when this option is set
77  if ($GLOBALS['TYPO3_AJAX']) {
78  $this->request = $this->request->withAttribute('isAjaxRequest', true);
79  } elseif (isset($this->request->getQueryParams()['M'])) {
80  $this->request = $this->request->withAttribute('isModuleRequest', true);
81  }
82 
83  $this->bootstrap->configure();
84  }
85 
92  public function run(callable $execute = null)
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 
106  protected function defineLegacyConstants()
107  {
108  define('TYPO3_MODE', 'BE');
109  }
110 
115  {
116  $currentScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
117 
118  // Activate "AJAX" handler when called with the GET variable ajaxID
119  if (!empty(GeneralUtility::_GET('ajaxID'))) {
120  $GLOBALS['TYPO3_AJAX'] = true;
121  // The following check is security relevant! DO NOT REMOVE!
122  } elseif (empty(GeneralUtility::_GET('M')) && substr($currentScript, -16) === '/typo3/index.php') {
123  // Allow backend login to work, disallow module access without authenticated backend user
124  define('TYPO3_PROCEED_IF_NO_USER', 1);
125  }
126  }
127 }