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