81e060d141642a7cc7960f3ebce09b7437ea200b
[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 */
116 public function getContext() {
117 return $this->context;
118 }
119
120 /**
121 * Prevent any unwanted output that may corrupt AJAX/compression.
122 * This does not interfere with "die()" or "echo"+"exit()" messages!
123 *
124 * @return \TYPO3\CMS\Core\Core\Bootstrap
125 * @internal This is not a public API method, do not use in own extensions
126 */
127 public function startOutputBuffering() {
128 ob_start();
129 return $this;
130 }
131
132 /**
133 * Run the base setup that checks server environment,
134 * determines pathes, populates base files and sets common configuration.
135 *
136 * Script execution will be aborted if something fails here.
137 *
138 * @param string $relativePathPart Relative path of the entry script back to document root
139 * @return \TYPO3\CMS\Core\Core\Bootstrap
140 * @internal This is not a public API method, do not use in own extensions
141 */
142 public function baseSetup($relativePathPart = '') {
143 \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run($relativePathPart);
144 return $this;
145 }
146
147 /**
148 * Redirect to install tool if LocalConfiguration.php is missing.
149 *
150 * @param string $pathUpToDocumentRoot Can contain eg. '../' if called from a sub directory
151 * @return \TYPO3\CMS\Core\Core\Bootstrap
152 * @internal This is not a public API method, do not use in own extensions
153 */
154 public function redirectToInstallerIfLocalConfigurationFileDoesNotExist($pathUpToDocumentRoot = '') {
155 /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
156 $configurationManager = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
157 if (!file_exists($configurationManager->getLocalConfigurationFileLocation())) {
158 require_once __DIR__ . '/../Utility/HttpUtility.php';
159 Utility\HttpUtility::redirect($pathUpToDocumentRoot . 'typo3/sysext/install/Start/Install.php');
160 }
161 return $this;
162 }
163
164 /**
165 * Includes LocalConfiguration.php and sets several
166 * global settings depending on configuration.
167 *
168 * @param boolean $allowCaching Whether to allow caching - affects cache_core (autoloader)
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 loadConfigurationAndInitialize($allowCaching = TRUE) {
173 $bootstrap = $this->getInstance();
174
175 $bootstrap->populateLocalConfiguration();
176
177 if (!$allowCaching) {
178 $bootstrap->setCoreCacheToNullBackend();
179 }
180
181 $bootstrap->defineDatabaseConstants()
182 ->defineUserAgentConstant()
183 ->registerExtDirectComponents()
184 ->initializeCachingFramework()
185 ->registerAutoloader()
186 ->checkUtf8DatabaseSettingsOrDie()
187 ->transferDeprecatedCurlSettings()
188 ->setCacheHashOptions()
189 ->enforceCorrectProxyAuthScheme()
190 ->setDefaultTimezone()
191 ->initializeL10nLocales()
192 ->configureImageProcessingOptions()
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 if (PHP_VERSION_ID < 50307) {
357 \TYPO3\CMS\Core\Compatibility\CompatbilityClassLoaderPhpBelow50307::registerAutoloader();
358 } else {
359 \TYPO3\CMS\Core\Core\ClassLoader::registerAutoloader();
360 }
361 return $this;
362 }
363
364 /**
365 * Checking for UTF-8 in the settings since TYPO3 4.5
366 *
367 * Since TYPO3 4.5, everything other than UTF-8 is deprecated.
368 *
369 * [SYS][setDBinit] is used to set the DB connection
370 * and both settings need to be adjusted for UTF-8 in order to work properly
371 *
372 * @return \TYPO3\CMS\Core\Core\Bootstrap
373 */
374 protected function checkUtf8DatabaseSettingsOrDie() {
375 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) &&
376 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1' &&
377 preg_match('/SET NAMES [\'"]?utf8[\'"]?/i', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE &&
378 TYPO3_enterInstallScript !== '1') {
379
380 // Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
381 die('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) .
382 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] . chr(10) . chr(10) .
383 'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) .
384 'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) .
385 'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.'
386 );
387 } else {
388 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
389 }
390 return $this;
391 }
392
393 /**
394 * Parse old curl options and set new http ones instead
395 *
396 * @TODO : This code segment must still be finished
397 * @return \TYPO3\CMS\Core\Core\Bootstrap
398 */
399 protected function transferDeprecatedCurlSettings() {
400 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
401 $proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
402 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
403 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
404 }
405 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
406 $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
407 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
408 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
409 }
410 return $this;
411 }
412
413 /**
414 * Set cacheHash options
415 *
416 * @return \TYPO3\CMS\Core\Core\Bootstrap
417 */
418 protected function setCacheHashOptions() {
419 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
420 'cachedParametersWhiteList' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
421 'excludedParameters' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
422 'requireCacheHashPresenceParameters' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE)
423 );
424 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
425 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
426 } else {
427 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
428 }
429 return $this;
430 }
431
432 /**
433 * $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] must be either
434 * 'digest' or 'basic' with fallback to 'basic'
435 *
436 * @return \TYPO3\CMS\Core\Core\Bootstrap
437 */
438 protected function enforceCorrectProxyAuthScheme() {
439 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?: ($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic');
440 return $this;
441 }
442
443 /**
444 * Set default timezone
445 *
446 * @return \TYPO3\CMS\Core\Core\Bootstrap
447 */
448 protected function setDefaultTimezone() {
449 $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
450 if (empty($timeZone)) {
451 // Time zone from the server environment (TZ env or OS query)
452 $defaultTimeZone = @date_default_timezone_get();
453 if ($defaultTimeZone !== '') {
454 $timeZone = $defaultTimeZone;
455 } else {
456 $timeZone = 'UTC';
457 }
458 }
459 // Set default to avoid E_WARNINGs with PHP > 5.3
460 date_default_timezone_set($timeZone);
461 return $this;
462 }
463
464 /**
465 * Initialize the locales handled by TYPO3
466 *
467 * @return \TYPO3\CMS\Core\Core\Bootstrap
468 */
469 protected function initializeL10nLocales() {
470 \TYPO3\CMS\Core\Localization\Locales::initialize();
471 return $this;
472 }
473
474 /**
475 * Based on the configuration of the image processing some options are forced
476 * to simplify configuration settings and combinations
477 *
478 * @return \TYPO3\CMS\Core\Core\Bootstrap
479 */
480 protected function configureImageProcessingOptions() {
481 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
482 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] = 0;
483 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = 0;
484 }
485 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
486 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'] = '';
487 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] = '';
488 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,png';
489 $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
490 }
491 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
492 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
493 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
494 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
495 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') {
496 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
497 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
498 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
499 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
500 }
501 }
502 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
503 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? 0 : 1;
504 }
505 return $this;
506 }
507
508 /**
509 * Convert type of "pageNotFound_handling" setting in case it was written as a
510 * string (e.g. if edited in Install Tool)
511 *
512 * @TODO : Remove, if the Install Tool handles such data types correctly
513 * @return \TYPO3\CMS\Core\Core\Bootstrap
514 */
515 protected function convertPageNotFoundHandlingToBoolean() {
516 if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
517 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
518 }
519 return $this;
520 }
521
522 /**
523 * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
524 *
525 * Note: Yes, this is possible in php! xdebug() is then a global function, even
526 * if registerGlobalDebugFunctions() is encapsulated in class scope.
527 *
528 * @return \TYPO3\CMS\Core\Core\Bootstrap
529 */
530 protected function registerGlobalDebugFunctions() {
531 require_once('GlobalDebugFunctions.php');
532 return $this;
533 }
534
535 /**
536 * Mail sending via Swift Mailer
537 *
538 * @return \TYPO3\CMS\Core\Core\Bootstrap
539 * @deprecated since 6.1, will be removed two versions later - will be removed together with \TYPO3\CMS\Core\Utility\MailUtility::mail()
540 */
541 protected function registerSwiftMailer() {
542 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] =
543 'TYPO3\\CMS\\Core\\Mail\\SwiftMailerAdapter';
544 return $this;
545 }
546
547 /**
548 * Configure and set up exception and error handling
549 *
550 * @return \TYPO3\CMS\Core\Core\Bootstrap
551 */
552 protected function configureExceptionHandling() {
553 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
554 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
555 // Turn error logging on/off.
556 if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
557 // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
558 if ($displayErrors == 2) {
559 if (Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
560 $displayErrors = 1;
561 } else {
562 $displayErrors = 0;
563 }
564 }
565 if ($displayErrors == 0) {
566 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
567 }
568 if ($displayErrors == 1) {
569 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
570 define('TYPO3_ERRORHANDLER_MODE', 'debug');
571 }
572 @ini_set('display_errors', $displayErrors);
573 } elseif (Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
574 // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
575 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
576 }
577 return $this;
578 }
579
580 /**
581 * Set PHP memory limit depending on value of
582 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
583 *
584 * @return \TYPO3\CMS\Core\Core\Bootstrap
585 */
586 protected function setMemoryLimit() {
587 if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
588 @ini_set('memory_limit', (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm'));
589 }
590 return $this;
591 }
592
593 /**
594 * Define TYPO3_REQUESTTYPE* constants
595 * so devs exactly know what type of request it is
596 *
597 * @return \TYPO3\CMS\Core\Core\Bootstrap
598 */
599 protected function defineTypo3RequestTypes() {
600 define('TYPO3_REQUESTTYPE_FE', 1);
601 define('TYPO3_REQUESTTYPE_BE', 2);
602 define('TYPO3_REQUESTTYPE_CLI', 4);
603 define('TYPO3_REQUESTTYPE_AJAX', 8);
604 define('TYPO3_REQUESTTYPE_INSTALL', 16);
605 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));
606 return $this;
607 }
608
609 /**
610 * Set up $GLOBALS['TYPO3_LOADED_EXT'] array with basic information
611 * about extensions.
612 *
613 * @param boolean $allowCaching
614 * @return \TYPO3\CMS\Core\Core\Bootstrap
615 */
616 protected function populateTypo3LoadedExtGlobal($allowCaching = TRUE) {
617 $GLOBALS['TYPO3_LOADED_EXT'] = Utility\ExtensionManagementUtility::loadTypo3LoadedExtensionInformation($allowCaching);
618 return $this;
619 }
620
621 /**
622 * Load extension configuration files (ext_localconf.php)
623 *
624 * The ext_localconf.php files in extensions are meant to make changes
625 * to the global $TYPO3_CONF_VARS configuration array.
626 *
627 * @param boolean $allowCaching
628 * @return \TYPO3\CMS\Core\Core\Bootstrap
629 */
630 protected function loadAdditionalConfigurationFromExtensions($allowCaching = TRUE) {
631 Utility\ExtensionManagementUtility::loadExtLocalconf($allowCaching);
632 return $this;
633 }
634
635 /**
636 * Initialize exception handling
637 *
638 * @return \TYPO3\CMS\Core\Core\Bootstrap
639 */
640 protected function initializeExceptionHandling() {
641 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
642 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
643 // Register an error handler for the given errorHandlerErrors
644 $errorHandler = Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']);
645 // Set errors which will be converted in an exception
646 $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
647 }
648 // Instantiate the exception handler once to make sure object is registered
649 // @TODO: Figure out if this is really needed
650 Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
651 }
652 return $this;
653 }
654
655 /**
656 * Extensions may register new caches, so we set the
657 * global cache array to the manager again at this point
658 *
659 * @return \TYPO3\CMS\Core\Core\Bootstrap
660 */
661 protected function setFinalCachingFrameworkCacheConfiguration() {
662 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
663 return $this;
664 }
665
666 /**
667 * Define logging and exception constants
668 *
669 * @return \TYPO3\CMS\Core\Core\Bootstrap
670 */
671 protected function defineLoggingAndExceptionConstants() {
672 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
673 define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
674 define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
675 return $this;
676 }
677
678 /**
679 * Unsetting reserved global variables:
680 * Those are set in "ext:core/ext_tables.php" file:
681 *
682 * @return \TYPO3\CMS\Core\Core\Bootstrap
683 */
684 protected function unsetReservedGlobalVariables() {
685 unset($GLOBALS['PAGES_TYPES']);
686 unset($GLOBALS['TCA']);
687 unset($GLOBALS['TBE_MODULES']);
688 unset($GLOBALS['TBE_STYLES']);
689 unset($GLOBALS['FILEICONS']);
690 // Those set in init.php:
691 unset($GLOBALS['WEBMOUNTS']);
692 unset($GLOBALS['FILEMOUNTS']);
693 unset($GLOBALS['BE_USER']);
694 // Those set otherwise:
695 unset($GLOBALS['TBE_MODULES_EXT']);
696 unset($GLOBALS['TCA_DESCR']);
697 unset($GLOBALS['LOCAL_LANG']);
698 unset($GLOBALS['TYPO3_AJAX']);
699 return $this;
700 }
701
702 /**
703 * Initialize database connection in $GLOBALS and connect if requested
704 *
705 * @return \TYPO3\CMS\Core\Core\Bootstrap
706 * @internal This is not a public API method, do not use in own extensions
707 */
708 public function initializeTypo3DbGlobal() {
709 /** @var $databaseConnection \TYPO3\CMS\Core\Database\DatabaseConnection */
710 $databaseConnection = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
711 $databaseConnection->setDatabaseName(TYPO3_db);
712 $databaseConnection->setDatabaseUsername(TYPO3_db_username);
713 $databaseConnection->setDatabasePassword(TYPO3_db_password);
714
715 $databaseHost = TYPO3_db_host;
716 if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])) {
717 $databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
718 } elseif (strpos($databaseHost, ':') > 0) {
719 // @TODO: Find a way to handle this case in the install tool and drop this
720 list($databaseHost, $databasePort) = explode(':', $databaseHost);
721 $databaseConnection->setDatabasePort($databasePort);
722 }
723 if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])) {
724 $databaseConnection->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
725 }
726 $databaseConnection->setDatabaseHost($databaseHost);
727
728 $databaseConnection->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
729
730 if (
731 isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect'])
732 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']
733 ) {
734 $databaseConnection->setPersistentDatabaseConnection(TRUE);
735 }
736
737 $isDatabaseHostLocalHost = $databaseHost === 'localhost' || $databaseHost === '127.0.0.1' || $databaseHost === '::1';
738 if (
739 isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress'])
740 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress']
741 && !$isDatabaseHostLocalHost
742 ) {
743 $databaseConnection->setConnectionCompression(TRUE);
744 }
745
746 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'])) {
747 $commandsAfterConnect = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(
748 LF,
749 str_replace('\' . LF . \'', LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']),
750 TRUE
751 );
752 $databaseConnection->setInitializeCommandsAfterConnect($commandsAfterConnect);
753 }
754
755 $GLOBALS['TYPO3_DB'] = $databaseConnection;
756
757 return $this;
758 }
759
760 /**
761 * Check adminOnly configuration variable and redirects
762 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
763 *
764 * @throws \RuntimeException
765 * @return \TYPO3\CMS\Core\Core\Bootstrap
766 * @internal This is not a public API method, do not use in own extensions
767 */
768 public function checkLockedBackendAndRedirectOrDie() {
769 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
770 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);
771 }
772 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
773 if (TYPO3_PROCEED_IF_NO_USER === 2) {
774
775 } else {
776 $fileContent = Utility\GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
777 if ($fileContent) {
778 header('Location: ' . $fileContent);
779 } else {
780 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);
781 }
782 die;
783 }
784 }
785 return $this;
786 }
787
788 /**
789 * Compare client IP with IPmaskList and exit the script run
790 * if the client is not allowed to access the backend
791 *
792 * @return \TYPO3\CMS\Core\Core\Bootstrap
793 * @internal This is not a public API method, do not use in own extensions
794 */
795 public function checkBackendIpOrDie() {
796 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
797 if (!Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
798 // Send Not Found header - if the webserver can make use of it
799 header('Status: 404 Not Found');
800 // Just point us away from here...
801 header('Location: http://');
802 // ... and exit good!
803 die;
804 }
805 }
806 return $this;
807 }
808
809 /**
810 * Check lockSSL configuration variable and redirect
811 * to https version of the backend if needed
812 *
813 * @return \TYPO3\CMS\Core\Core\Bootstrap
814 * @internal This is not a public API method, do not use in own extensions
815 */
816 public function checkSslBackendAndRedirectIfNeeded() {
817 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
818 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
819 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
820 } else {
821 $sslPortSuffix = '';
822 }
823 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
824 $requestStr = substr(Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
825 if ($requestStr === 'index.php' && !Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
826 list(, $url) = explode('://', Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 2);
827 list($server, $address) = explode('/', $url, 2);
828 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
829 die;
830 }
831 } elseif (!Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
832 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
833 list(, $url) = explode('://', Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
834 list($server, $address) = explode('/', $url, 2);
835 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
836 } else {
837 // Send Not Found header - if the webserver can make use of it...
838 header('Status: 404 Not Found');
839 // Just point us away from here...
840 header('Location: http://');
841 }
842 // ... and exit good!
843 die;
844 }
845 }
846 return $this;
847 }
848
849 /**
850 * Load TCA for frontend
851 *
852 * This method is *only* executed in frontend scope. The idea is to execute the
853 * whole TCA and ext_tables (which manipulate TCA) on first frontend access,
854 * and then cache the full TCA on disk to be used for the next run again.
855 *
856 * This way, ext_tables.php ist not executed every time, but $GLOBALS['TCA']
857 * is still always there.
858 *
859 * @return \TYPO3\CMS\Core\Core\Bootstrap
860 * @internal This is not a public API method, do not use in own extensions
861 */
862 public function loadCachedTca() {
863 $cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
864 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
865 $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
866 if ($codeCache->has($cacheIdentifier)) {
867 $codeCache->requireOnce($cacheIdentifier);
868 } else {
869 $this->loadExtensionTables(TRUE);
870 $phpCodeToCache = '$GLOBALS[\'TCA\'] = ';
871 $phpCodeToCache .= Utility\ArrayUtility::arrayExport($GLOBALS['TCA']);
872 $phpCodeToCache .= ';';
873 $codeCache->set($cacheIdentifier, $phpCodeToCache);
874 }
875 return $this;
876 }
877
878 /**
879 * Load ext_tables and friends.
880 *
881 * This will mainly set up $TCA and several other global arrays
882 * through API's like extMgm.
883 * Executes ext_tables.php files of loaded extensions or the
884 * according cache file if exists.
885 *
886 * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
887 * @return \TYPO3\CMS\Core\Core\Bootstrap
888 * @internal This is not a public API method, do not use in own extensions
889 */
890 public function loadExtensionTables($allowCaching = TRUE) {
891 Utility\ExtensionManagementUtility::loadBaseTca($allowCaching);
892 Utility\ExtensionManagementUtility::loadExtTables($allowCaching);
893 $this->executeExtTablesAdditionalFile();
894 $this->runExtTablesPostProcessingHooks();
895 return $this;
896 }
897
898 /**
899 * Execute TYPO3_extTableDef_script if defined and exists
900 *
901 * Note: For backwards compatibility some global variables are
902 * explicitly set as global to be used without $GLOBALS[] in
903 * the extension table script. It is discouraged to access variables like
904 * $TBE_MODULES directly, but we can not prohibit
905 * this without heavily breaking backwards compatibility.
906 *
907 * @TODO : We could write a scheduler / reports module or an update checker
908 * @TODO : It should be defined, which global arrays are ok to be manipulated
909 *
910 * @return void
911 */
912 protected function executeExtTablesAdditionalFile() {
913 // It is discouraged to use those global variables directly, but we
914 // can not prohibit this without breaking backwards compatibility
915 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
916 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
917 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
918 global $_EXTKEY;
919 // Load additional ext tables script if the file exists
920 $extTablesFile = PATH_typo3conf . TYPO3_extTableDef_script;
921 if (file_exists($extTablesFile) && is_file($extTablesFile)) {
922 include $extTablesFile;
923 }
924
925 // Apply TCA onto tables to be categorized
926 \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->applyTca();
927 }
928
929 /**
930 * Check for registered ext tables hooks and run them
931 *
932 * @throws \UnexpectedValueException
933 * @return void
934 */
935 protected function runExtTablesPostProcessingHooks() {
936 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
937 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
938 /** @var $hookObject \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface */
939 $hookObject = Utility\GeneralUtility::getUserObj($classReference);
940 if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
941 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface', 1320585902);
942 }
943 $hookObject->processData();
944 }
945 }
946 }
947
948 /**
949 * Initialize sprite manager
950 *
951 * @return \TYPO3\CMS\Core\Core\Bootstrap
952 * @internal This is not a public API method, do not use in own extensions
953 */
954 public function initializeSpriteManager() {
955 \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
956 return $this;
957 }
958
959 /**
960 * Initialize backend user object in globals
961 *
962 * @return \TYPO3\CMS\Core\Core\Bootstrap
963 * @internal This is not a public API method, do not use in own extensions
964 */
965 public function initializeBackendUser() {
966 /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
967 $backendUser = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
968 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
969 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
970 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
971 $backendUser->OS = TYPO3_OS;
972 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
973 $backendUser->dontSetCookie = TRUE;
974 }
975 // The global must be available very early, because methods below
976 // might trigger code which relies on it. See: #45625
977 $GLOBALS['BE_USER'] = $backendUser;
978 $backendUser->start();
979 $backendUser->checkCLIuser();
980 $backendUser->backendCheckLogin();
981 return $this;
982 }
983
984 /**
985 * Initialize backend user mount points
986 *
987 * @return \TYPO3\CMS\Core\Core\Bootstrap
988 * @internal This is not a public API method, do not use in own extensions
989 */
990 public function initializeBackendUserMounts() {
991 // Includes deleted mount pages as well! @TODO: Figure out why ...
992 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
993 $GLOBALS['BE_USER']->getFileStorages();
994 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->groupData['filemounts'];
995 return $this;
996 }
997
998 /**
999 * Initialize language object
1000 *
1001 * @return \TYPO3\CMS\Core\Core\Bootstrap
1002 * @internal This is not a public API method, do not use in own extensions
1003 */
1004 public function initializeLanguageObject() {
1005 /** @var $GLOBALS['LANG'] \TYPO3\CMS\Lang\LanguageService */
1006 $GLOBALS['LANG'] = Utility\GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService');
1007 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
1008 return $this;
1009 }
1010
1011 /**
1012 * Throw away all output that may have happened during bootstrapping by weird extensions
1013 *
1014 * @return \TYPO3\CMS\Core\Core\Bootstrap
1015 * @internal This is not a public API method, do not use in own extensions
1016 */
1017 public function endOutputBufferingAndCleanPreviousOutput() {
1018 ob_clean();
1019 return $this;
1020 }
1021
1022 /**
1023 * Initialize output compression if configured
1024 *
1025 * @return \TYPO3\CMS\Core\Core\Bootstrap
1026 * @internal This is not a public API method, do not use in own extensions
1027 */
1028 public function initializeOutputCompression() {
1029 if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
1030 if (Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
1031 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
1032 }
1033 ob_start('ob_gzhandler');
1034 }
1035 return $this;
1036 }
1037
1038 /**
1039 * Initialize module menu object
1040 *
1041 * @return \TYPO3\CMS\Core\Core\Bootstrap
1042 * @internal This is not a public API method, do not use in own extensions
1043 */
1044 public function initializeModuleMenuObject() {
1045 /** @var $moduleMenuUtility \TYPO3\CMS\Backend\Module\ModuleController */
1046 $moduleMenuUtility = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleController');
1047 $moduleMenuUtility->createModuleMenu();
1048 return $this;
1049 }
1050
1051 /**
1052 * Things that should be performed to shut down the framework.
1053 * This method is called in all important scripts for a clean
1054 * shut down of the system.
1055 *
1056 * @return \TYPO3\CMS\Core\Core\Bootstrap
1057 * @internal This is not a public API method, do not use in own extensions
1058 */
1059 public function shutdown() {
1060 if (PHP_VERSION_ID < 50307) {
1061 \TYPO3\CMS\Core\Compatibility\CompatbilityClassLoaderPhpBelow50307::unregisterAutoloader();
1062 } else {
1063 \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader();
1064 }
1065 return $this;
1066 }
1067
1068 /**
1069 * Provides an instance of "template" for backend-modules to
1070 * work with.
1071 *
1072 * @return \TYPO3\CMS\Core\Core\Bootstrap
1073 * @internal This is not a public API method, do not use in own extensions
1074 */
1075 public function initializeBackendTemplate() {
1076 $GLOBALS['TBE_TEMPLATE'] = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
1077 return $this;
1078 }
1079
1080 }
1081
1082
1083 ?>