[TASK] Move configuration code from bootstrap to ext:install
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / Bootstrap.php
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use \TYPO3\CMS\Core\Utility;
31
32 require __DIR__ . '/SystemEnvironmentBuilder.php';
33
34 /**
35 * This class encapsulates bootstrap related methods.
36 * It is required directly as the very first thing in entry scripts and
37 * used to define all base things like constants and pathes and so on.
38 *
39 * Most methods in this class have dependencies to each other. They can
40 * not be called in arbitrary order. The methods are ordered top down, so
41 * a method at the beginning has lower dependencies than a method further
42 * down. Do not fiddle with the load order in own scripts except you know
43 * exactly what you are doing!
44 *
45 * @author Christian Kuhn <lolli@schwarzbu.ch>
46 */
47 class Bootstrap {
48
49 /**
50 * @var \TYPO3\CMS\Core\Core\Bootstrap
51 */
52 static protected $instance = NULL;
53
54 /**
55 * Unique Request ID
56 *
57 * @var string
58 */
59 protected $requestId;
60
61 /**
62 * The application context
63 *
64 * @var \TYPO3\CMS\Core\Core\ApplicationContext
65 */
66 protected $context;
67
68 /**
69 * Disable direct creation of this object.
70 * Set unique requestId and the application context
71 *
72 * @var string Application context
73 */
74 protected function __construct($context) {
75 $this->requestId = uniqid();
76 $this->context = new ApplicationContext($context);
77 }
78
79 /**
80 * Disable direct cloning of this object.
81 */
82 protected function __clone() {
83
84 }
85
86 /**
87 * Return 'this' as singleton
88 *
89 * @return \TYPO3\CMS\Core\Core\Bootstrap
90 * @internal This is not a public API method, do not use in own extensions
91 */
92 static public function getInstance() {
93 if (is_null(self::$instance)) {
94 require_once(__DIR__ . '/ApplicationContext.php');
95 $context = trim(getenv('TYPO3_CONTEXT'), '"\' ') ? : 'Production';
96 self::$instance = new \TYPO3\CMS\Core\Core\Bootstrap($context);
97 }
98 return self::$instance;
99 }
100
101 /**
102 * Gets the request's unique ID
103 *
104 * @return string Unique request ID
105 * @internal This is not a public API method, do not use in own extensions
106 */
107 public function getRequestId() {
108 return $this->requestId;
109 }
110
111 /**
112 * Returns the context this bootstrap was started in.
113 *
114 * @return \TYPO3\CMS\Core\Core\ApplicationContext The context encapsulated in an object
115 * @internal This is not a public API method, do not use in own extensions. Use \TYPO3\CMS\Core\Utility\GeneralUtility::getContext() instead
116 */
117 public function getContext() {
118 return $this->context;
119 }
120
121 /**
122 * Prevent any unwanted output that may corrupt AJAX/compression.
123 * This does not interfere with "die()" or "echo"+"exit()" messages!
124 *
125 * @return \TYPO3\CMS\Core\Core\Bootstrap
126 * @internal This is not a public API method, do not use in own extensions
127 */
128 public function startOutputBuffering() {
129 ob_start();
130 return $this;
131 }
132
133 /**
134 * Run the base setup that checks server environment,
135 * determines pathes, populates base files and sets common configuration.
136 *
137 * Script execution will be aborted if something fails here.
138 *
139 * @param string $relativePathPart Relative path of the entry script back to document root
140 * @return \TYPO3\CMS\Core\Core\Bootstrap
141 * @internal This is not a public API method, do not use in own extensions
142 */
143 public function baseSetup($relativePathPart = '') {
144 \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run($relativePathPart);
145 Utility\GeneralUtility::presetContext($this->context);
146 return $this;
147 }
148
149 /**
150 * Redirect to install tool if LocalConfiguration.php is missing.
151 *
152 * @param string $pathUpToDocumentRoot Can contain eg. '../' if called from a sub directory
153 * @return \TYPO3\CMS\Core\Core\Bootstrap
154 * @internal This is not a public API method, do not use in own extensions
155 */
156 public function redirectToInstallerIfLocalConfigurationFileDoesNotExist($pathUpToDocumentRoot = '') {
157 /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
158 $configurationManager = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
159 if (!file_exists($configurationManager->getLocalConfigurationFileLocation())) {
160 require_once __DIR__ . '/../Utility/HttpUtility.php';
161 Utility\HttpUtility::redirect($pathUpToDocumentRoot . 'typo3/sysext/install/Start/Install.php');
162 }
163 return $this;
164 }
165
166 /**
167 * Includes LocalConfiguration.php and sets several
168 * global settings depending on configuration.
169 *
170 * @param boolean $allowCaching Whether to allow caching - affects cache_core (autoloader)
171 * @return \TYPO3\CMS\Core\Core\Bootstrap
172 * @internal This is not a public API method, do not use in own extensions
173 */
174 public function loadConfigurationAndInitialize($allowCaching = TRUE) {
175 $bootstrap = $this->getInstance();
176
177 $bootstrap->populateLocalConfiguration();
178
179 if (!$allowCaching) {
180 $bootstrap->setCoreCacheToNullBackend();
181 }
182
183 $bootstrap->defineDatabaseConstants()
184 ->defineUserAgentConstant()
185 ->registerExtDirectComponents()
186 ->initializeCachingFramework()
187 ->registerAutoloader()
188 ->checkUtf8DatabaseSettingsOrDie()
189 ->transferDeprecatedCurlSettings()
190 ->setCacheHashOptions()
191 ->setDefaultTimezone()
192 ->initializeL10nLocales()
193 ->convertPageNotFoundHandlingToBoolean()
194 ->registerGlobalDebugFunctions()
195 // SwiftMailerAdapter is
196 // @deprecated since 6.1, will be removed two versions later - will be removed together with \TYPO3\CMS\Core\Utility\MailUtility::mail()
197 ->registerSwiftMailer()
198 ->configureExceptionHandling()
199 ->setMemoryLimit()
200 ->defineTypo3RequestTypes();
201 return $this;
202 }
203
204 /**
205 * Load TYPO3_LOADED_EXT and ext_localconf
206 *
207 * @param boolean $allowCaching
208 * @return \TYPO3\CMS\Core\Core\Bootstrap
209 * @internal This is not a public API method, do not use in own extensions
210 */
211 public function loadTypo3LoadedExtAndExtLocalconf($allowCaching = TRUE) {
212 $this->getInstance()
213 ->populateTypo3LoadedExtGlobal($allowCaching)
214 ->loadAdditionalConfigurationFromExtensions($allowCaching);
215 return $this;
216 }
217
218 /**
219 * Load TYPO3_LOADED_EXT, recreate class loader registry and load ext_localconf
220 *
221 * @return \TYPO3\CMS\Core\Core\Bootstrap
222 * @internal This is not a public API method, do not use in own extensions
223 */
224 public function reloadTypo3LoadedExtAndClassLoaderAndExtLocalconf() {
225 $bootstrap = $this->getInstance();
226 $bootstrap->populateTypo3LoadedExtGlobal(FALSE);
227 \TYPO3\CMS\Core\Core\ClassLoader::loadClassLoaderCache();
228 $bootstrap->loadAdditionalConfigurationFromExtensions(FALSE);
229 return $this;
230 }
231
232 /**
233 * Sets up additional configuration applied in all scopes
234 *
235 * @return \TYPO3\CMS\Core\Core\Bootstrap
236 * @internal This is not a public API method, do not use in own extensions
237 */
238 public function applyAdditionalConfigurationSettings() {
239 $this->getInstance()
240 ->initializeExceptionHandling()
241 ->setFinalCachingFrameworkCacheConfiguration()
242 ->defineLoggingAndExceptionConstants()
243 ->unsetReservedGlobalVariables();
244 return $this;
245 }
246
247 /**
248 * Throws an exception if no browser could be identified
249 *
250 * @return \TYPO3\CMS\Core\Core\Bootstrap
251 * @throws \RuntimeException
252 * @internal This is not a public API method, do not use in own extensions
253 */
254 public function checkValidBrowserOrDie() {
255 // Checks for proper browser
256 if (empty($GLOBALS['CLIENT']['BROWSER'])) {
257 throw new \RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
258 }
259 return $this;
260 }
261
262 /**
263 * Populate the local configuration.
264 * Merge default TYPO3_CONF_VARS with content of typo3conf/LocalConfiguration.php,
265 * execute typo3conf/AdditionalConfiguration.php, define database related constants.
266 *
267 * @return \TYPO3\CMS\Core\Core\Bootstrap
268 * @internal This is not a public API method, do not use in own extensions
269 */
270 public function populateLocalConfiguration() {
271 /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
272 $configurationManager = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
273 $configurationManager->exportConfiguration();
274 return $this;
275 }
276
277 /**
278 * Set cache_core to null backend, effectively disabling eg. the autoloader cache
279 *
280 * @return \TYPO3\CMS\Core\Core\Bootstrap
281 * @internal This is not a public API method, do not use in own extensions
282 */
283 public function setCoreCacheToNullBackend() {
284 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['backend']
285 = 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend';
286 return $this;
287 }
288
289 /**
290 * Define database constants
291 *
292 * @return \TYPO3\CMS\Core\Core\Bootstrap
293 */
294 protected function defineDatabaseConstants() {
295 define('TYPO3_db', $GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
296 define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
297 define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
298 define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
299 define('TYPO3_extTableDef_script',
300 isset($GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript'])
301 ? $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']
302 : 'extTables.php');
303 return $this;
304 }
305
306 /**
307 * Define user agent constant
308 *
309 * @return \TYPO3\CMS\Core\Core\Bootstrap
310 */
311 protected function defineUserAgentConstant() {
312 define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
313 return $this;
314 }
315
316 /**
317 * Register default ExtDirect components
318 *
319 * @return \TYPO3\CMS\Core\Core\Bootstrap
320 */
321 protected function registerExtDirectComponents() {
322 if (TYPO3_MODE === 'BE') {
323 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.DataProvider', 'TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeDataProvider', 'web', 'user,group');
324 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.Commands', 'TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeCommands', 'web', 'user,group');
325 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.ContextMenuDataProvider', 'TYPO3\\CMS\\Backend\\ContextMenu\\Pagetree\\Extdirect\\ContextMenuConfiguration', 'web', 'user,group');
326 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.LiveSearchActions.ExtDirect', 'TYPO3\\CMS\\Backend\\Search\\LiveSearch\\ExtDirect\\LiveSearchDataProvider', 'web_list', 'user,group');
327 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.BackendUserSettings.ExtDirect', 'TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
328 if (Utility\ExtensionManagementUtility::isLoaded('context_help')) {
329 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.CSH.ExtDirect', 'TYPO3\\CMS\\ContextHelp\\ExtDirect\\ContextHelpDataProvider');
330 }
331 Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.ExtDirectStateProvider.ExtDirect', 'TYPO3\\CMS\\Backend\\InterfaceState\\ExtDirect\\DataProvider');
332 Utility\ExtensionManagementUtility::registerExtDirectComponent(
333 'TYPO3.Components.DragAndDrop.CommandController',
334 Utility\ExtensionManagementUtility::extPath('backend') . 'Classes/View/PageLayout/Extdirect/ExtdirectPageCommands.php:TYPO3\\CMS\\Backend\\View\\PageLayout\\ExtDirect\\ExtdirectPageCommands', 'web', 'user,group'
335 );
336 }
337 return $this;
338 }
339
340 /**
341 * Initialize caching framework
342 *
343 * @return \TYPO3\CMS\Core\Core\Bootstrap
344 */
345 protected function initializeCachingFramework() {
346 \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework();
347 return $this;
348 }
349
350 /**
351 * Register autoloader
352 *
353 * @return \TYPO3\CMS\Core\Core\Bootstrap
354 */
355 protected function registerAutoloader() {
356 \TYPO3\CMS\Core\Core\ClassLoader::registerAutoloader();
357 return $this;
358 }
359
360 /**
361 * Checking for UTF-8 in the settings since TYPO3 4.5
362 *
363 * Since TYPO3 4.5, everything other than UTF-8 is deprecated.
364 *
365 * [SYS][setDBinit] is used to set the DB connection
366 * and both settings need to be adjusted for UTF-8 in order to work properly
367 *
368 * @return \TYPO3\CMS\Core\Core\Bootstrap
369 */
370 protected function checkUtf8DatabaseSettingsOrDie() {
371 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) &&
372 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1' &&
373 preg_match('/SET NAMES [\'"]?utf8[\'"]?/i', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE &&
374 TYPO3_enterInstallScript !== '1') {
375
376 // Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
377 die('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) .
378 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] . chr(10) . chr(10) .
379 'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) .
380 'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) .
381 'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.'
382 );
383 } else {
384 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
385 }
386 return $this;
387 }
388
389 /**
390 * Parse old curl options and set new http ones instead
391 *
392 * @TODO : This code segment must still be finished
393 * @return \TYPO3\CMS\Core\Core\Bootstrap
394 */
395 protected function transferDeprecatedCurlSettings() {
396 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
397 $proxyParts = Utility\GeneralUtility::revExplode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
398 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
399 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
400 }
401 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
402 $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
403 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
404 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
405 }
406 return $this;
407 }
408
409 /**
410 * Set cacheHash options
411 *
412 * @return \TYPO3\CMS\Core\Core\Bootstrap
413 */
414 protected function setCacheHashOptions() {
415 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
416 'cachedParametersWhiteList' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
417 'excludedParameters' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
418 'requireCacheHashPresenceParameters' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE)
419 );
420 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
421 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
422 } else {
423 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
424 }
425 return $this;
426 }
427
428 /**
429 * Set default timezone
430 *
431 * @return \TYPO3\CMS\Core\Core\Bootstrap
432 */
433 protected function setDefaultTimezone() {
434 $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
435 if (empty($timeZone)) {
436 // Time zone from the server environment (TZ env or OS query)
437 $defaultTimeZone = @date_default_timezone_get();
438 if ($defaultTimeZone !== '') {
439 $timeZone = $defaultTimeZone;
440 } else {
441 $timeZone = 'UTC';
442 }
443 }
444 // Set default to avoid E_WARNINGs with PHP > 5.3
445 date_default_timezone_set($timeZone);
446 return $this;
447 }
448
449 /**
450 * Initialize the locales handled by TYPO3
451 *
452 * @return \TYPO3\CMS\Core\Core\Bootstrap
453 */
454 protected function initializeL10nLocales() {
455 \TYPO3\CMS\Core\Localization\Locales::initialize();
456 return $this;
457 }
458
459 /**
460 * Convert type of "pageNotFound_handling" setting in case it was written as a
461 * string (e.g. if edited in Install Tool)
462 *
463 * @TODO : Remove, if the Install Tool handles such data types correctly
464 * @return \TYPO3\CMS\Core\Core\Bootstrap
465 */
466 protected function convertPageNotFoundHandlingToBoolean() {
467 if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
468 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
469 }
470 return $this;
471 }
472
473 /**
474 * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
475 *
476 * Note: Yes, this is possible in php! xdebug() is then a global function, even
477 * if registerGlobalDebugFunctions() is encapsulated in class scope.
478 *
479 * @return \TYPO3\CMS\Core\Core\Bootstrap
480 */
481 protected function registerGlobalDebugFunctions() {
482 require_once('GlobalDebugFunctions.php');
483 return $this;
484 }
485
486 /**
487 * Mail sending via Swift Mailer
488 *
489 * @return \TYPO3\CMS\Core\Core\Bootstrap
490 * @deprecated since 6.1, will be removed two versions later - will be removed together with \TYPO3\CMS\Core\Utility\MailUtility::mail()
491 */
492 protected function registerSwiftMailer() {
493 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] =
494 'TYPO3\\CMS\\Core\\Mail\\SwiftMailerAdapter';
495 return $this;
496 }
497
498 /**
499 * Configure and set up exception and error handling
500 *
501 * @return \TYPO3\CMS\Core\Core\Bootstrap
502 */
503 protected function configureExceptionHandling() {
504 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
505 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
506 // Turn error logging on/off.
507 if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
508 // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
509 if ($displayErrors == 2) {
510 if (Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
511 $displayErrors = 1;
512 } else {
513 $displayErrors = 0;
514 }
515 }
516 if ($displayErrors == 0) {
517 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
518 }
519 if ($displayErrors == 1) {
520 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
521 define('TYPO3_ERRORHANDLER_MODE', 'debug');
522 }
523 @ini_set('display_errors', $displayErrors);
524 } elseif (Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
525 // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
526 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
527 }
528 return $this;
529 }
530
531 /**
532 * Set PHP memory limit depending on value of
533 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
534 *
535 * @return \TYPO3\CMS\Core\Core\Bootstrap
536 */
537 protected function setMemoryLimit() {
538 if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
539 @ini_set('memory_limit', (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm'));
540 }
541 return $this;
542 }
543
544 /**
545 * Define TYPO3_REQUESTTYPE* constants
546 * so devs exactly know what type of request it is
547 *
548 * @return \TYPO3\CMS\Core\Core\Bootstrap
549 */
550 protected function defineTypo3RequestTypes() {
551 define('TYPO3_REQUESTTYPE_FE', 1);
552 define('TYPO3_REQUESTTYPE_BE', 2);
553 define('TYPO3_REQUESTTYPE_CLI', 4);
554 define('TYPO3_REQUESTTYPE_AJAX', 8);
555 define('TYPO3_REQUESTTYPE_INSTALL', 16);
556 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));
557 return $this;
558 }
559
560 /**
561 * Set up $GLOBALS['TYPO3_LOADED_EXT'] array with basic information
562 * about extensions.
563 *
564 * @param boolean $allowCaching
565 * @return \TYPO3\CMS\Core\Core\Bootstrap
566 */
567 protected function populateTypo3LoadedExtGlobal($allowCaching = TRUE) {
568 $GLOBALS['TYPO3_LOADED_EXT'] = Utility\ExtensionManagementUtility::loadTypo3LoadedExtensionInformation($allowCaching);
569 return $this;
570 }
571
572 /**
573 * Load extension configuration files (ext_localconf.php)
574 *
575 * The ext_localconf.php files in extensions are meant to make changes
576 * to the global $TYPO3_CONF_VARS configuration array.
577 *
578 * @param boolean $allowCaching
579 * @return \TYPO3\CMS\Core\Core\Bootstrap
580 */
581 protected function loadAdditionalConfigurationFromExtensions($allowCaching = TRUE) {
582 Utility\ExtensionManagementUtility::loadExtLocalconf($allowCaching);
583 return $this;
584 }
585
586 /**
587 * Initialize exception handling
588 *
589 * @return \TYPO3\CMS\Core\Core\Bootstrap
590 */
591 protected function initializeExceptionHandling() {
592 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
593 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
594 // Register an error handler for the given errorHandlerErrors
595 $errorHandler = Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']);
596 // Set errors which will be converted in an exception
597 $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
598 }
599 // Instantiate the exception handler once to make sure object is registered
600 // @TODO: Figure out if this is really needed
601 Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
602 }
603 return $this;
604 }
605
606 /**
607 * Extensions may register new caches, so we set the
608 * global cache array to the manager again at this point
609 *
610 * @return \TYPO3\CMS\Core\Core\Bootstrap
611 */
612 protected function setFinalCachingFrameworkCacheConfiguration() {
613 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
614 return $this;
615 }
616
617 /**
618 * Define logging and exception constants
619 *
620 * @return \TYPO3\CMS\Core\Core\Bootstrap
621 */
622 protected function defineLoggingAndExceptionConstants() {
623 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
624 define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
625 define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
626 return $this;
627 }
628
629 /**
630 * Unsetting reserved global variables:
631 * Those are set in "ext:core/ext_tables.php" file:
632 *
633 * @return \TYPO3\CMS\Core\Core\Bootstrap
634 */
635 protected function unsetReservedGlobalVariables() {
636 unset($GLOBALS['PAGES_TYPES']);
637 unset($GLOBALS['TCA']);
638 unset($GLOBALS['TBE_MODULES']);
639 unset($GLOBALS['TBE_STYLES']);
640 unset($GLOBALS['FILEICONS']);
641 // Those set in init.php:
642 unset($GLOBALS['WEBMOUNTS']);
643 unset($GLOBALS['FILEMOUNTS']);
644 unset($GLOBALS['BE_USER']);
645 // Those set otherwise:
646 unset($GLOBALS['TBE_MODULES_EXT']);
647 unset($GLOBALS['TCA_DESCR']);
648 unset($GLOBALS['LOCAL_LANG']);
649 unset($GLOBALS['TYPO3_AJAX']);
650 return $this;
651 }
652
653 /**
654 * Initialize database connection in $GLOBALS and connect if requested
655 *
656 * @return \TYPO3\CMS\Core\Core\Bootstrap
657 * @internal This is not a public API method, do not use in own extensions
658 */
659 public function initializeTypo3DbGlobal() {
660 /** @var $databaseConnection \TYPO3\CMS\Core\Database\DatabaseConnection */
661 $databaseConnection = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
662 $databaseConnection->setDatabaseName(TYPO3_db);
663 $databaseConnection->setDatabaseUsername(TYPO3_db_username);
664 $databaseConnection->setDatabasePassword(TYPO3_db_password);
665
666 $databaseHost = TYPO3_db_host;
667 if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])) {
668 $databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
669 } elseif (strpos($databaseHost, ':') > 0) {
670 // @TODO: Find a way to handle this case in the install tool and drop this
671 list($databaseHost, $databasePort) = explode(':', $databaseHost);
672 $databaseConnection->setDatabasePort($databasePort);
673 }
674 if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])) {
675 $databaseConnection->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
676 }
677 $databaseConnection->setDatabaseHost($databaseHost);
678
679 $databaseConnection->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
680
681 if (
682 isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect'])
683 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']
684 ) {
685 $databaseConnection->setPersistentDatabaseConnection(TRUE);
686 }
687
688 $isDatabaseHostLocalHost = $databaseHost === 'localhost' || $databaseHost === '127.0.0.1' || $databaseHost === '::1';
689 if (
690 isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress'])
691 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress']
692 && !$isDatabaseHostLocalHost
693 ) {
694 $databaseConnection->setConnectionCompression(TRUE);
695 }
696
697 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'])) {
698 $commandsAfterConnect = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(
699 LF,
700 str_replace('\' . LF . \'', LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']),
701 TRUE
702 );
703 $databaseConnection->setInitializeCommandsAfterConnect($commandsAfterConnect);
704 }
705
706 $GLOBALS['TYPO3_DB'] = $databaseConnection;
707
708 return $this;
709 }
710
711 /**
712 * Check adminOnly configuration variable and redirects
713 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
714 *
715 * @throws \RuntimeException
716 * @return \TYPO3\CMS\Core\Core\Bootstrap
717 * @internal This is not a public API method, do not use in own extensions
718 */
719 public function checkLockedBackendAndRedirectOrDie() {
720 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
721 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);
722 }
723 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
724 if (TYPO3_PROCEED_IF_NO_USER === 2) {
725
726 } else {
727 $fileContent = Utility\GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
728 if ($fileContent) {
729 header('Location: ' . $fileContent);
730 } else {
731 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);
732 }
733 die;
734 }
735 }
736 return $this;
737 }
738
739 /**
740 * Compare client IP with IPmaskList and exit the script run
741 * if the client is not allowed to access the backend
742 *
743 * @return \TYPO3\CMS\Core\Core\Bootstrap
744 * @internal This is not a public API method, do not use in own extensions
745 */
746 public function checkBackendIpOrDie() {
747 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
748 if (!Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
749 // Send Not Found header - if the webserver can make use of it
750 header('Status: 404 Not Found');
751 // Just point us away from here...
752 header('Location: http://');
753 // ... and exit good!
754 die;
755 }
756 }
757 return $this;
758 }
759
760 /**
761 * Check lockSSL configuration variable and redirect
762 * to https version of the backend if needed
763 *
764 * @return \TYPO3\CMS\Core\Core\Bootstrap
765 * @internal This is not a public API method, do not use in own extensions
766 */
767 public function checkSslBackendAndRedirectIfNeeded() {
768 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
769 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
770 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
771 } else {
772 $sslPortSuffix = '';
773 }
774 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
775 $requestStr = substr(Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
776 if ($requestStr === 'index.php' && !Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
777 list(, $url) = explode('://', Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 2);
778 list($server, $address) = explode('/', $url, 2);
779 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
780 die;
781 }
782 } elseif (!Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
783 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
784 list(, $url) = explode('://', Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
785 list($server, $address) = explode('/', $url, 2);
786 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
787 } else {
788 // Send Not Found header - if the webserver can make use of it...
789 header('Status: 404 Not Found');
790 // Just point us away from here...
791 header('Location: http://');
792 }
793 // ... and exit good!
794 die;
795 }
796 }
797 return $this;
798 }
799
800 /**
801 * Load TCA for frontend
802 *
803 * This method is *only* executed in frontend scope. The idea is to execute the
804 * whole TCA and ext_tables (which manipulate TCA) on first frontend access,
805 * and then cache the full TCA on disk to be used for the next run again.
806 *
807 * This way, ext_tables.php ist not executed every time, but $GLOBALS['TCA']
808 * is still always there.
809 *
810 * @return \TYPO3\CMS\Core\Core\Bootstrap
811 * @internal This is not a public API method, do not use in own extensions
812 */
813 public function loadCachedTca() {
814 $cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
815 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
816 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
817 if ($codeCache->has($cacheIdentifier)) {
818 $codeCache->requireOnce($cacheIdentifier);
819 } else {
820 $this->loadExtensionTables(TRUE);
821 $phpCodeToCache = '$GLOBALS[\'TCA\'] = ' . var_export($GLOBALS['TCA'], TRUE) . ';';
822 $codeCache->set($cacheIdentifier, $phpCodeToCache);
823 }
824 return $this;
825 }
826
827 /**
828 * Load ext_tables and friends.
829 *
830 * This will mainly set up $TCA and several other global arrays
831 * through API's like extMgm.
832 * Executes ext_tables.php files of loaded extensions or the
833 * according cache file if exists.
834 *
835 * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
836 * @return \TYPO3\CMS\Core\Core\Bootstrap
837 * @internal This is not a public API method, do not use in own extensions
838 */
839 public function loadExtensionTables($allowCaching = TRUE) {
840 Utility\ExtensionManagementUtility::loadBaseTca($allowCaching);
841 Utility\ExtensionManagementUtility::loadExtTables($allowCaching);
842 $this->executeExtTablesAdditionalFile();
843 $this->runExtTablesPostProcessingHooks();
844 return $this;
845 }
846
847 /**
848 * Execute TYPO3_extTableDef_script if defined and exists
849 *
850 * Note: For backwards compatibility some global variables are
851 * explicitly set as global to be used without $GLOBALS[] in
852 * the extension table script. It is discouraged to access variables like
853 * $TBE_MODULES directly, but we can not prohibit
854 * this without heavily breaking backwards compatibility.
855 *
856 * @TODO : We could write a scheduler / reports module or an update checker
857 * @TODO : It should be defined, which global arrays are ok to be manipulated
858 *
859 * @return void
860 */
861 protected function executeExtTablesAdditionalFile() {
862 // It is discouraged to use those global variables directly, but we
863 // can not prohibit this without breaking backwards compatibility
864 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
865 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
866 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
867 global $_EXTKEY;
868 // Load additional ext tables script if the file exists
869 $extTablesFile = PATH_typo3conf . TYPO3_extTableDef_script;
870 if (file_exists($extTablesFile) && is_file($extTablesFile)) {
871 include $extTablesFile;
872 }
873
874 // Apply TCA onto tables to be categorized
875 \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->applyTca();
876 }
877
878 /**
879 * Check for registered ext tables hooks and run them
880 *
881 * @throws \UnexpectedValueException
882 * @return void
883 */
884 protected function runExtTablesPostProcessingHooks() {
885 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
886 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
887 /** @var $hookObject \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface */
888 $hookObject = Utility\GeneralUtility::getUserObj($classReference);
889 if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
890 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface', 1320585902);
891 }
892 $hookObject->processData();
893 }
894 }
895 }
896
897 /**
898 * Initialize sprite manager
899 *
900 * @return \TYPO3\CMS\Core\Core\Bootstrap
901 * @internal This is not a public API method, do not use in own extensions
902 */
903 public function initializeSpriteManager() {
904 \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
905 return $this;
906 }
907
908 /**
909 * Initialize backend user object in globals
910 *
911 * @return \TYPO3\CMS\Core\Core\Bootstrap
912 * @internal This is not a public API method, do not use in own extensions
913 */
914 public function initializeBackendUser() {
915 /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
916 $backendUser = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
917 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
918 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
919 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
920 $backendUser->OS = TYPO3_OS;
921 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
922 $backendUser->dontSetCookie = TRUE;
923 }
924 // The global must be available very early, because methods below
925 // might trigger code which relies on it. See: #45625
926 $GLOBALS['BE_USER'] = $backendUser;
927 $backendUser->start();
928 $backendUser->checkCLIuser();
929 $backendUser->backendCheckLogin();
930 return $this;
931 }
932
933 /**
934 * Initialize backend user mount points
935 *
936 * @return \TYPO3\CMS\Core\Core\Bootstrap
937 * @internal This is not a public API method, do not use in own extensions
938 */
939 public function initializeBackendUserMounts() {
940 // Includes deleted mount pages as well! @TODO: Figure out why ...
941 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
942 $GLOBALS['BE_USER']->getFileStorages();
943 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->groupData['filemounts'];
944 return $this;
945 }
946
947 /**
948 * Initialize language object
949 *
950 * @return \TYPO3\CMS\Core\Core\Bootstrap
951 * @internal This is not a public API method, do not use in own extensions
952 */
953 public function initializeLanguageObject() {
954 /** @var $GLOBALS['LANG'] \TYPO3\CMS\Lang\LanguageService */
955 $GLOBALS['LANG'] = Utility\GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService');
956 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
957 return $this;
958 }
959
960 /**
961 * Throw away all output that may have happened during bootstrapping by weird extensions
962 *
963 * @return \TYPO3\CMS\Core\Core\Bootstrap
964 * @internal This is not a public API method, do not use in own extensions
965 */
966 public function endOutputBufferingAndCleanPreviousOutput() {
967 ob_clean();
968 return $this;
969 }
970
971 /**
972 * Initialize output compression if configured
973 *
974 * @return \TYPO3\CMS\Core\Core\Bootstrap
975 * @internal This is not a public API method, do not use in own extensions
976 */
977 public function initializeOutputCompression() {
978 if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
979 if (Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
980 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
981 }
982 ob_start('ob_gzhandler');
983 }
984 return $this;
985 }
986
987 /**
988 * Initialize module menu object
989 *
990 * @return \TYPO3\CMS\Core\Core\Bootstrap
991 * @internal This is not a public API method, do not use in own extensions
992 */
993 public function initializeModuleMenuObject() {
994 /** @var $moduleMenuUtility \TYPO3\CMS\Backend\Module\ModuleController */
995 $moduleMenuUtility = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleController');
996 $moduleMenuUtility->createModuleMenu();
997 return $this;
998 }
999
1000 /**
1001 * Things that should be performed to shut down the framework.
1002 * This method is called in all important scripts for a clean
1003 * shut down of the system.
1004 *
1005 * @return \TYPO3\CMS\Core\Core\Bootstrap
1006 * @internal This is not a public API method, do not use in own extensions
1007 */
1008 public function shutdown() {
1009 \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader();
1010 return $this;
1011 }
1012
1013 /**
1014 * Provides an instance of "template" for backend-modules to
1015 * work with.
1016 *
1017 * @return \TYPO3\CMS\Core\Core\Bootstrap
1018 * @internal This is not a public API method, do not use in own extensions
1019 */
1020 public function initializeBackendTemplate() {
1021 $GLOBALS['TBE_TEMPLATE'] = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
1022 return $this;
1023 }
1024 }
1025 ?>