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