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