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