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