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