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