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