[BUGFIX] Fix early calls to makeInstance
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / Bootstrap.php
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3
4 require 'SystemEnvironmentBuilder.php';
5
6 /**
7 * This class encapsulates bootstrap related methods.
8 * It is required directly as the very first thing in entry scripts and
9 * used to define all base things like constants and pathes and so on.
10 *
11 * Most methods in this class have dependencies to each other. They can
12 * not be called in arbitrary order. The methods are ordered top down, so
13 * a method at the beginning has lower dependencies than a method further
14 * down. Do not fiddle with the load order in own scripts except you know
15 * exactly what you are doing!
16 *
17 * @author Christian Kuhn <lolli@schwarzbu.ch>
18 */
19 class Bootstrap {
20
21 /**
22 * @var \TYPO3\CMS\Core\Core\Bootstrap
23 */
24 static protected $instance = NULL;
25
26 /**
27 * Unique Request ID
28 *
29 * @var string
30 */
31 protected $requestId;
32
33 /**
34 * Disable direct creation of this object.
35 */
36 protected function __construct() {
37 $this->requestId = uniqid();
38 }
39
40 /**
41 * Disable direct cloning of this object.
42 */
43 protected function __clone() {
44
45 }
46
47 /**
48 * Return 'this' as singleton
49 *
50 * @return \TYPO3\CMS\Core\Core\Bootstrap
51 */
52 static public function getInstance() {
53 if (is_null(self::$instance)) {
54 self::$instance = new \TYPO3\CMS\Core\Core\Bootstrap();
55 }
56 return self::$instance;
57 }
58
59 /**
60 * Gets the request's unique ID
61 *
62 * @return string Unique request ID
63 */
64 public function getRequestId() {
65 return $this->requestId;
66 }
67
68 /**
69 * Prevent any unwanted output that may corrupt AJAX/compression.
70 * This does not interfere with "die()" or "echo"+"exit()" messages!
71 *
72 * @return \TYPO3\CMS\Core\Core\Bootstrap
73 */
74 public function startOutputBuffering() {
75 ob_start();
76 return $this;
77 }
78
79 /**
80 * Run the base setup that checks server environment,
81 * determines pathes, populates base files and sets common configuration.
82 *
83 * Script execution will be aborted if something fails here.
84 *
85 * @param string $relativePathPart Relative path of the entry script back to document root
86 * @return \TYPO3\CMS\Core\Core\Bootstrap
87 */
88 public function baseSetup($relativePathPart = '') {
89 \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run($relativePathPart);
90 return $this;
91 }
92
93 /**
94 * Throws an exception if no browser could be identified
95 *
96 * @return \TYPO3\CMS\Core\Core\Bootstrap
97 * @throws \RuntimeException
98 */
99 public function checkValidBrowserOrDie() {
100 // Checks for proper browser
101 if (empty($GLOBALS['CLIENT']['BROWSER'])) {
102 throw new \RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
103 }
104 return $this;
105 }
106
107 /**
108 * Register default ExtDirect components
109 *
110 * @return \TYPO3\CMS\Core\Core\Bootstrap
111 */
112 public function registerExtDirectComponents() {
113 if (TYPO3_MODE === 'BE') {
114 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.DataProvider', 'TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeDataProvider', 'web', 'user,group');
115 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.Commands', 'TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeCommands', 'web', 'user,group');
116 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.ContextMenuDataProvider', 'TYPO3\\CMS\\Backend\\ContextMenu\\Pagetree\\Extdirect\\ContextMenuConfiguration', 'web', 'user,group');
117 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.LiveSearchActions.ExtDirect', 'TYPO3\\CMS\\Backend\\Search\\LiveSearch\\ExtDirect\\LiveSearchDataProvider', 'web_list', 'user,group');
118 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.BackendUserSettings.ExtDirect', 'TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
119 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.CSH.ExtDirect', 'TYPO3\\CMS\\ContextHelp\\ExtDirect\\ContextHelpDataProvider');
120 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.ExtDirectStateProvider.ExtDirect', 'TYPO3\\CMS\\Backend\\InterfaceState\\ExtDirect\\DataProvider');
121 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.DragAndDrop.CommandController',
122 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('backend') . 'Classes/View/PageLayout/Extdirect/ExtdirectPageCommands.php:TYPO3\\CMS\\Backend\\View\\PageLayout\\ExtDirect\\ExtdirectPageCommands', 'web', 'user,group');
123 }
124 return $this;
125 }
126
127 /**
128 * Populate the local configuration.
129 * Merge default TYPO3_CONF_VARS with content of typo3conf/LocalConfiguration.php,
130 * execute typo3conf/AdditionalConfiguration.php, define database related constants.
131 *
132 * @return \TYPO3\CMS\Core\Core\Bootstrap
133 */
134 public function populateLocalConfiguration() {
135 try {
136 // We need an early instance of the configuration manager.
137 // Since makeInstance relies on the object configuration, we create it here with new instead
138 // and register it as singleton instance for later use.
139 $configuarationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
140 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', $configuarationManager);
141 $configuarationManager->exportConfiguration();
142 } catch (\Exception $e) {
143 die($e->getMessage());
144 }
145 define('TYPO3_db', $GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
146 define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
147 define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
148 define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
149 define('TYPO3_extTableDef_script', $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']);
150 unset($GLOBALS['TYPO3_CONF_VARS']['DB']);
151 define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
152 return $this;
153 }
154
155 /**
156 * Redirect to install tool if database host and database are not defined
157 *
158 * @return \TYPO3\CMS\Core\Core\Bootstrap
159 */
160 public function redirectToInstallToolIfDatabaseCredentialsAreMissing() {
161 if (!TYPO3_db_host && !TYPO3_db) {
162 \TYPO3\CMS\Core\Utility\HttpUtility::redirect('install/index.php?mode=123&step=1&password=joh316');
163 }
164 return $this;
165 }
166
167 /**
168 * Initialize caching framework
169 *
170 * @return \TYPO3\CMS\Core\Core\Bootstrap
171 */
172 public function initializeCachingFramework() {
173 \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework();
174 return $this;
175 }
176
177 /**
178 * Register autoloader
179 *
180 * @return \TYPO3\CMS\Core\Core\Bootstrap
181 */
182 public function registerAutoloader() {
183 if (PHP_VERSION_ID < 50307) {
184 \TYPO3\CMS\Core\Compatibility\CompatbilityClassLoaderPhpBelow50307::registerAutoloader();
185 } else {
186 \TYPO3\CMS\Core\Core\ClassLoader::registerAutoloader();
187 }
188 return $this;
189 }
190
191 /**
192 * Checking for UTF-8 in the settings since TYPO3 4.5
193 *
194 * Since TYPO3 4.5, everything other than UTF-8 is deprecated.
195 *
196 * [BE][forceCharset] is set to the charset that TYPO3 is using
197 * [SYS][setDBinit] is used to set the DB connection
198 * and both settings need to be adjusted for UTF-8 in order to work properly
199 *
200 * @return \TYPO3\CMS\Core\Core\Bootstrap
201 */
202 public function checkUtf8DatabaseSettingsOrDie() {
203 // Check if [BE][forceCharset] has been set in localconf.php
204 if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'])) {
205 // die() unless we're already on UTF-8
206 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] != 'utf-8' && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] && TYPO3_enterInstallScript !== '1') {
207 die('This installation was just upgraded to a new TYPO3 version. Since TYPO3 4.7, utf-8 is always enforced.<br />' . 'The configuration option $GLOBALS[\'TYPO3_CONF_VARS\'][BE][forceCharset] was marked as deprecated in TYPO3 4.5 and is now ignored.<br />' . 'You have configured the value to something different, which is not supported anymore.<br />' . 'Please proceed to the Update Wizard in the TYPO3 Install Tool to update your configuration.');
208 } else {
209 unset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
210 }
211 }
212 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1' && preg_match('/SET NAMES utf8/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE && TYPO3_enterInstallScript !== '1') {
213 // Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
214 die('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) . $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] . chr(10) . chr(10) . 'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) . 'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) . 'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.');
215 } else {
216 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
217 }
218 return $this;
219 }
220
221 /**
222 * Parse old curl options and set new http ones instead
223 *
224 * @TODO : This code segment must still be finished
225 * @return \TYPO3\CMS\Core\Core\Bootstrap
226 */
227 public function transferDeprecatedCurlSettings() {
228 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
229 $proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
230 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
231 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
232 }
233 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
234 $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
235 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
236 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
237 }
238 return $this;
239 }
240
241 /**
242 * Set cacheHash options
243 *
244 * @return \TYPO3\CMS\Core\Core\Bootstrap
245 */
246 public function setCacheHashOptions() {
247 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
248 'cachedParametersWhiteList' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
249 'excludedParameters' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
250 'requireCacheHashPresenceParameters' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE)
251 );
252 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
253 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
254 } else {
255 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
256 }
257 return $this;
258 }
259
260 /**
261 * $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] must be either
262 * 'digest' or 'basic' with fallback to 'basic'
263 *
264 * @return \TYPO3\CMS\Core\Core\Bootstrap
265 */
266 public function enforceCorrectProxyAuthScheme() {
267 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?: ($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic');
268 return $this;
269 }
270
271 /**
272 * Set default timezone
273 *
274 * @return \TYPO3\CMS\Core\Core\Bootstrap
275 */
276 public function setDefaultTimezone() {
277 $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
278 if (empty($timeZone)) {
279 // Time zone from the server environment (TZ env or OS query)
280 $defaultTimeZone = @date_default_timezone_get();
281 if ($defaultTimeZone !== '') {
282 $timeZone = $defaultTimeZone;
283 } else {
284 $timeZone = 'UTC';
285 }
286 }
287 // Set default to avoid E_WARNINGs with PHP > 5.3
288 date_default_timezone_set($timeZone);
289 return $this;
290 }
291
292 /**
293 * Initialize the locales handled by TYPO3
294 *
295 * @return \TYPO3\CMS\Core\Core\Bootstrap
296 */
297 public function initializeL10nLocales() {
298 \TYPO3\CMS\Core\Localization\Locales::initialize();
299 return $this;
300 }
301
302 /**
303 * Based on the configuration of the image processing some options are forced
304 * to simplify configuration settings and combinations
305 *
306 * @return \TYPO3\CMS\Core\Core\Bootstrap
307 */
308 public function configureImageProcessingOptions() {
309 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
310 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] = 0;
311 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = 0;
312 }
313 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
314 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'] = '';
315 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] = '';
316 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,png';
317 $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
318 }
319 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
320 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
321 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
322 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
323 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') {
324 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
325 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
326 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
327 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
328 }
329 }
330 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
331 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? 0 : 1;
332 }
333 return $this;
334 }
335
336 /**
337 * Convert type of "pageNotFound_handling" setting in case it was written as a
338 * string (e.g. if edited in Install Tool)
339 *
340 * @TODO : Remove, if the Install Tool handles such data types correctly
341 * @return \TYPO3\CMS\Core\Core\Bootstrap
342 */
343 public function convertPageNotFoundHandlingToBoolean() {
344 if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
345 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
346 }
347 return $this;
348 }
349
350 /**
351 * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
352 *
353 * Note: Yes, this is possible in php! xdebug() is then a global function, even
354 * if registerGlobalDebugFunctions() is encapsulated in class scope.
355 *
356 * @return \TYPO3\CMS\Core\Core\Bootstrap
357 */
358 public function registerGlobalDebugFunctions() {
359 require_once('GlobalDebugFunctions.php');
360 return $this;
361 }
362
363 /**
364 * Mail sending via Swift Mailer
365 *
366 * @return \TYPO3\CMS\Core\Core\Bootstrap
367 */
368 public function registerSwiftMailer() {
369 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] = 'TYPO3\\CMS\\Core\\Mail\\SwiftMailerAdapter';
370 return $this;
371 }
372
373 /**
374 * Configure and set up exception and error handling
375 *
376 * @return \TYPO3\CMS\Core\Core\Bootstrap
377 */
378 public function configureExceptionHandling() {
379 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
380 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
381 // Turn error logging on/off.
382 if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
383 // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
384 if ($displayErrors == 2) {
385 if (\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
386 $displayErrors = 1;
387 } else {
388 $displayErrors = 0;
389 }
390 }
391 if ($displayErrors == 0) {
392 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
393 }
394 if ($displayErrors == 1) {
395 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
396 define('TYPO3_ERRORHANDLER_MODE', 'debug');
397 }
398 @ini_set('display_errors', $displayErrors);
399 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
400 // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
401 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
402 }
403 return $this;
404 }
405
406 /**
407 * Set PHP memory limit depending on value of
408 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
409 *
410 * @return \TYPO3\CMS\Core\Core\Bootstrap
411 */
412 public function setMemoryLimit() {
413 if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
414 @ini_set('memory_limit', (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm'));
415 }
416 return $this;
417 }
418
419 /**
420 * Define TYPO3_REQUESTTYPE* constants
421 * so devs exactly know what type of request it is
422 *
423 * @return \TYPO3\CMS\Core\Core\Bootstrap
424 */
425 public function defineTypo3RequestTypes() {
426 define('TYPO3_REQUESTTYPE_FE', 1);
427 define('TYPO3_REQUESTTYPE_BE', 2);
428 define('TYPO3_REQUESTTYPE_CLI', 4);
429 define('TYPO3_REQUESTTYPE_AJAX', 8);
430 define('TYPO3_REQUESTTYPE_INSTALL', 16);
431 define('TYPO3_REQUESTTYPE', (TYPO3_MODE == 'FE' ? TYPO3_REQUESTTYPE_FE : 0) | (TYPO3_MODE == 'BE' ? TYPO3_REQUESTTYPE_BE : 0) | (defined('TYPO3_cliMode') && TYPO3_cliMode ? TYPO3_REQUESTTYPE_CLI : 0) | (defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript ? TYPO3_REQUESTTYPE_INSTALL : 0) | ($GLOBALS['TYPO3_AJAX'] ? TYPO3_REQUESTTYPE_AJAX : 0));
432 return $this;
433 }
434
435 /**
436 * Set up $GLOBALS['TYPO3_LOADED_EXT'] array with basic information
437 * about extensions.
438 *
439 * @param boolean $allowCaching
440 * @return \TYPO3\CMS\Core\Core\Bootstrap
441 */
442 public function populateTypo3LoadedExtGlobal($allowCaching = TRUE) {
443 $GLOBALS['TYPO3_LOADED_EXT'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadTypo3LoadedExtensionInformation($allowCaching);
444 return $this;
445 }
446
447 /**
448 * Load extension configuration files (ext_localconf.php)
449 *
450 * The ext_localconf.php files in extensions are meant to make changes
451 * to the global $TYPO3_CONF_VARS configuration array.
452 *
453 * @param boolean $allowCaching
454 * @return \TYPO3\CMS\Core\Core\Bootstrap
455 */
456 public function loadAdditionalConfigurationFromExtensions($allowCaching = TRUE) {
457 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtLocalconf($allowCaching);
458 return $this;
459 }
460
461 /**
462 * Write deprecation log if deprecated extCache setting was set in the instance.
463 *
464 * @return \TYPO3\CMS\Core\Core\Bootstrap
465 * @deprecated since 6.0, the check will be removed two version later.
466 */
467 public function deprecationLogForOldExtCacheSetting() {
468 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] !== -1) {
469 \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('Setting $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'extCache\'] is unused and can be removed from localconf.php');
470 }
471 return $this;
472 }
473
474 /**
475 * Initialize exception handling
476 *
477 * @return \TYPO3\CMS\Core\Core\Bootstrap
478 */
479 public function initializeExceptionHandling() {
480 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
481 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
482 // Register an error handler for the given errorHandlerErrors
483 $errorHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']);
484 // Set errors which will be converted in an exception
485 $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
486 }
487 // Instantiate the exception handler once to make sure object is registered
488 // @TODO: Figure out if this is really needed
489 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
490 }
491 return $this;
492 }
493
494 /**
495 * Extensions may register new caches, so we set the
496 * global cache array to the manager again at this point
497 *
498 * @return \TYPO3\CMS\Core\Core\Bootstrap
499 */
500 public function setFinalCachingFrameworkCacheConfiguration() {
501 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
502 return $this;
503 }
504
505 /**
506 * Define logging and exception constants
507 *
508 * @return \TYPO3\CMS\Core\Core\Bootstrap
509 */
510 public function defineLoggingAndExceptionConstants() {
511 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
512 define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
513 define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
514 return $this;
515 }
516
517 /**
518 * Unsetting reserved global variables:
519 * Those which are/can be set in "stddb/tables.php" files:
520 *
521 * @return \TYPO3\CMS\Core\Core\Bootstrap
522 */
523 public function unsetReservedGlobalVariables() {
524 unset($GLOBALS['PAGES_TYPES']);
525 unset($GLOBALS['TCA']);
526 unset($GLOBALS['TBE_MODULES']);
527 unset($GLOBALS['TBE_STYLES']);
528 unset($GLOBALS['FILEICONS']);
529 // Those set in init.php:
530 unset($GLOBALS['WEBMOUNTS']);
531 unset($GLOBALS['FILEMOUNTS']);
532 unset($GLOBALS['BE_USER']);
533 // Those set otherwise:
534 unset($GLOBALS['TBE_MODULES_EXT']);
535 unset($GLOBALS['TCA_DESCR']);
536 unset($GLOBALS['LOCAL_LANG']);
537 unset($GLOBALS['TYPO3_AJAX']);
538 return $this;
539 }
540
541 /**
542 * Initialize t3lib_db in $GLOBALS and connect if requested
543 *
544 * @param boolean $connect Whether or not the db should be connected already
545 * @return \TYPO3\CMS\Core\Core\Bootstrap
546 */
547 public function initializeTypo3DbGlobal($connect = TRUE) {
548 /** @var TYPO3_DB t3lib_db */
549 $GLOBALS['TYPO3_DB'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
550 $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
551 if ($connect) {
552 $this->establishDatabaseConnection();
553 }
554 return $this;
555 }
556
557 /**
558 * Check adminOnly configuration variable and redirects
559 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
560 *
561 * @throws \RuntimeException
562 * @return \TYPO3\CMS\Core\Core\Bootstrap
563 */
564 public function checkLockedBackendAndRedirectOrDie() {
565 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
566 throw new \RuntimeException('TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly']) . '".', 1294586847);
567 }
568 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
569 if (TYPO3_PROCEED_IF_NO_USER === 2) {
570
571 } else {
572 $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
573 if ($fileContent) {
574 header('Location: ' . $fileContent);
575 } else {
576 throw new \RuntimeException('TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.', 1294586848);
577 }
578 die;
579 }
580 }
581 return $this;
582 }
583
584 /**
585 * Compare client IP with IPmaskList and exit the script run
586 * if the client is not allowed to access the backend
587 *
588 * @return \TYPO3\CMS\Core\Core\Bootstrap
589 */
590 public function checkBackendIpOrDie() {
591 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
592 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
593 // Send Not Found header - if the webserver can make use of it
594 header('Status: 404 Not Found');
595 // Just point us away from here...
596 header('Location: http://');
597 // ... and exit good!
598 die;
599 }
600 }
601 return $this;
602 }
603
604 /**
605 * Check lockSSL configuration variable and redirect
606 * to https version of the backend if needed
607 *
608 * @return \TYPO3\CMS\Core\Core\Bootstrap
609 */
610 public function checkSslBackendAndRedirectIfNeeded() {
611 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
612 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
613 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
614 } else {
615 $sslPortSuffix = '';
616 }
617 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
618 $requestStr = substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
619 if ($requestStr === 'index.php' && !\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
620 list(, $url) = explode('://', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 2);
621 list($server, $address) = explode('/', $url, 2);
622 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
623 die;
624 }
625 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
626 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
627 list(, $url) = explode('://', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
628 list($server, $address) = explode('/', $url, 2);
629 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
630 } else {
631 // Send Not Found header - if the webserver can make use of it...
632 header('Status: 404 Not Found');
633 // Just point us away from here...
634 header('Location: http://');
635 }
636 // ... and exit good!
637 die;
638 }
639 }
640 return $this;
641 }
642
643 /**
644 * Establish connection to the database
645 *
646 * @return \TYPO3\CMS\Core\Core\Bootstrap
647 */
648 public function establishDatabaseConnection() {
649 $GLOBALS['TYPO3_DB']->connectDB();
650 return $this;
651 }
652
653 /**
654 * Load ext_tables and friends.
655 *
656 * This will mainly set up $TCA and several other global arrays
657 * through API's like extMgm.
658 * Executes ext_tables.php files of loaded extensions or the
659 * according cache file if exists.
660 *
661 * Note: For backwards compatibility some global variables are
662 * explicitly set as global to be used without $GLOBALS[] in
663 * ext_tables.php. It is discouraged to access variables like
664 * $TBE_MODULES directly in ext_tables.php, but we can not prohibit
665 * this without heavily breaking backwards compatibility.
666 *
667 * @TODO : We could write a scheduler / reports module or an update checker
668 * @TODO : It should be defined, which global arrays are ok to be manipulated
669 * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
670 * @return \TYPO3\CMS\Core\Core\Bootstrap
671 */
672 public function loadExtensionTables($allowCaching = TRUE) {
673 // It is discouraged to use those global variables directly, but we
674 // can not prohibit this without breaking backwards compatibility
675 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
676 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
677 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
678 global $_EXTKEY;
679 // Include standard tables.php file
680 require PATH_t3lib . 'stddb/tables.php';
681 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtTables($allowCaching);
682 // Load additional ext tables script if registered
683 if (TYPO3_extTableDef_script) {
684 include PATH_typo3conf . TYPO3_extTableDef_script;
685 }
686 // Run post hook for additional manipulation
687 $this->runExtTablesPostProcessingHooks();
688 return $this;
689 }
690
691 /**
692 * Check for registered ext tables hooks and run them
693 *
694 * @throws \UnexpectedValueException
695 * @return \TYPO3\CMS\Core\Core\Bootstrap
696 */
697 protected function runExtTablesPostProcessingHooks() {
698 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
699 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
700 /** @var $hookObject \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface */
701 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classReference);
702 if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
703 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface', 1320585902);
704 }
705 $hookObject->processData();
706 }
707 }
708 return $this;
709 }
710
711 /**
712 * Initialize sprite manager
713 *
714 * @return \TYPO3\CMS\Core\Core\Bootstrap
715 */
716 public function initializeSpriteManager() {
717 \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
718 return $this;
719 }
720
721 /**
722 * Initialize backend user object in globals
723 *
724 * @return \TYPO3\CMS\Core\Core\Bootstrap
725 */
726 public function initializeBackendUser() {
727 /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
728 $backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
729 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
730 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
731 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
732 $backendUser->OS = TYPO3_OS;
733 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
734 $backendUser->dontSetCookie = TRUE;
735 }
736 $backendUser->start();
737 $backendUser->checkCLIuser();
738 $backendUser->backendCheckLogin();
739 $GLOBALS['BE_USER'] = $backendUser;
740 return $this;
741 }
742
743 /**
744 * Initialize backend user mount points
745 *
746 * @return \TYPO3\CMS\Core\Core\Bootstrap
747 */
748 public function initializeBackendUserMounts() {
749 // Includes deleted mount pages as well! @TODO: Figure out why ...
750 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
751 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
752 return $this;
753 }
754
755 /**
756 * Initialize language object
757 *
758 * @return \TYPO3\CMS\Core\Core\Bootstrap
759 */
760 public function initializeLanguageObject() {
761 /** @var $GLOBALS['LANG'] \TYPO3\CMS\Lang\LanguageService */
762 $GLOBALS['LANG'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService');
763 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
764 return $this;
765 }
766
767 /**
768 * Throw away all output that may have happened during bootstrapping by weird extensions
769 *
770 * @return \TYPO3\CMS\Core\Core\Bootstrap
771 */
772 public function endOutputBufferingAndCleanPreviousOutput() {
773 ob_clean();
774 return $this;
775 }
776
777 /**
778 * Initialize output compression if configured
779 *
780 * @return \TYPO3\CMS\Core\Core\Bootstrap
781 */
782 public function initializeOutputCompression() {
783 if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
784 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
785 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
786 }
787 ob_start('ob_gzhandler');
788 }
789 return $this;
790 }
791
792 /**
793 * Initialize module menu object
794 *
795 * @return \TYPO3\CMS\Core\Core\Bootstrap
796 */
797 public function initializeModuleMenuObject() {
798 /** @var $moduleMenuUtility Typo3_BackendModule_Utility */
799 $moduleMenuUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleController');
800 $moduleMenuUtility->createModuleMenu();
801 return $this;
802 }
803
804 /**
805 * Things that should be performed to shut down the framework.
806 * This method is called in all important scripts for a clean
807 * shut down of the system.
808 *
809 * @return \TYPO3\CMS\Core\Core\Bootstrap
810 */
811 public function shutdown() {
812 if (PHP_VERSION_ID < 50307) {
813 \TYPO3\CMS\Core\Compatibility\CompatbilityClassLoaderPhpBelow50307::unregisterAutoloader();
814 } else {
815 \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader();
816 }
817 return $this;
818 }
819
820 /**
821 * Provides an instance of "template" for backend-modules to
822 * work with.
823 *
824 * @return \TYPO3\CMS\Core\Core\Bootstrap
825 */
826 public function initializeBackendTemplate() {
827 $GLOBALS['TBE_TEMPLATE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
828 return $this;
829 }
830
831 }
832
833
834 ?>