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