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