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