TYPO3 CMS  TYPO3_6-2
Bootstrap.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3 
18 
32 class Bootstrap {
33 
37  static protected $instance = NULL;
38 
44  protected $requestId;
45 
52 
56  protected $earlyInstances = array();
57 
61  protected $installToolPath;
62 
67 
72 
79  protected function __construct($applicationContext) {
80  $this->requestId = substr(md5(uniqid('', TRUE)), 0, 13);
81  $this->applicationContext = new ApplicationContext($applicationContext);
82  }
83 
87  protected function __clone() {
88 
89  }
90 
97  static public function getInstance() {
98  if (is_null(static::$instance)) {
99  require_once(__DIR__ . '/../Exception.php');
100  require_once(__DIR__ . '/ApplicationContext.php');
101  $applicationContext = getenv('TYPO3_CONTEXT') ?: (getenv('REDIRECT_TYPO3_CONTEXT') ?: 'Production');
102  self::$instance = new static($applicationContext);
103  // Establish an alias for Flow/Package interoperability
104  class_alias(get_class(static::$instance), 'TYPO3\\Flow\\Core\\Bootstrap');
105  }
106  return static::$instance;
107  }
108 
115  public function getRequestId() {
116  return $this->requestId;
117  }
118 
126  public function getApplicationContext() {
128  }
129 
137  public function startOutputBuffering() {
138  ob_start();
139  return $this;
140  }
141 
152  public function baseSetup($relativePathPart = '') {
153  $composerClassLoader = $this->initializeComposerClassLoader();
154  $this->setEarlyInstance('Composer\\Autoload\\ClassLoader', $composerClassLoader);
155  SystemEnvironmentBuilder::run($relativePathPart);
156  Utility\GeneralUtility::presetApplicationContext($this->applicationContext);
157  return $this;
158  }
159 
163  protected function initializeComposerClassLoader() {
164  $respectComposerPackagesForClassLoading = getenv('TYPO3_COMPOSER_AUTOLOAD') ?: (getenv('REDIRECT_TYPO3_COMPOSER_AUTOLOAD') ?: NULL);
165  $possiblePaths = array();
166  if (!empty($respectComposerPackagesForClassLoading)) {
167  $possiblePaths['distribution'] = __DIR__ . '/../../../../../../Packages/Libraries/autoload.php';
168  }
169  $possiblePaths['fallback'] = __DIR__ . '/../../../../contrib/vendor/autoload.php';
170  foreach ($possiblePaths as $possiblePath) {
171  if (file_exists($possiblePath)) {
172  return include $possiblePath;
173  }
174  }
175  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);
176  }
177 
185  public function redirectToInstallerIfEssentialConfigurationDoesNotExist($pathUpToDocumentRoot = '') {
186  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
187  $this->setEarlyInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', $configurationManager);
188  if (!file_exists($configurationManager->getLocalConfigurationFileLocation()) || !file_exists(PATH_typo3conf . 'PackageStates.php')) {
189  define('TYPO3_enterInstallScript', '1');
190  $this->defineTypo3RequestTypes();
191  require_once __DIR__ . '/../Utility/HttpUtility.php';
192  Utility\HttpUtility::redirect($pathUpToDocumentRoot . 'typo3/sysext/install/Start/Install.php');
193  }
194  return $this;
195  }
196 
206  public function setEarlyInstance($objectName, $instance) {
207  $this->earlyInstances[$objectName] = $instance;
208  }
209 
217  public function getEarlyInstance($objectName) {
218  if (!isset($this->earlyInstances[$objectName])) {
219  throw new \TYPO3\CMS\Core\Exception('Unknown early instance "' . $objectName . '"', 1365167380);
220  }
221  return $this->earlyInstances[$objectName];
222  }
223 
229  public function getEarlyInstances() {
230  return $this->earlyInstances;
231  }
232 
242  public function loadConfigurationAndInitialize($allowCaching = TRUE, $packageManagerClassName = 'TYPO3\\CMS\\Core\\Package\\PackageManager') {
243  $this->initializeClassLoader()
244  ->populateLocalConfiguration();
245  if (!$allowCaching) {
247  }
249  ->initializeClassLoaderCaches()
250  ->initializePackageManagement($packageManagerClassName)
251  ->initializeRuntimeActivatedPackagesFromConfiguration();
252 
253  $this->defineDatabaseConstants()
254  ->defineUserAgentConstant()
255  ->registerExtDirectComponents()
256  ->transferDeprecatedCurlSettings()
257  ->setCacheHashOptions()
258  ->setDefaultTimezone()
259  ->initializeL10nLocales()
260  ->convertPageNotFoundHandlingToBoolean()
261  ->registerGlobalDebugFunctions()
262  // SwiftMailerAdapter is
263  // @deprecated since 6.1, will be removed two versions later - will be removed together with \TYPO3\CMS\Core\Utility\MailUtility::mail()
264  ->registerSwiftMailer()
265  ->configureExceptionHandling()
266  ->initializeExceptionHandling()
267  ->setMemoryLimit()
268  ->defineTypo3RequestTypes();
269  return $this;
270  }
271 
278  public function initializeClassLoader() {
279  $classLoader = new ClassLoader($this->applicationContext);
280  $this->setEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassLoader', $classLoader);
281  $classLoader->setRuntimeClassLoadingInformationFromAutoloadRegistry((array) include __DIR__ . '/../../ext_autoload.php');
282  $classAliasMap = new ClassAliasMap();
283  $classAliasMap->injectClassLoader($classLoader);
284  $classAliasMap->injectComposerClassLoader($this->getEarlyInstance('Composer\\Autoload\\ClassLoader'));
285  $this->setEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassAliasMap', $classAliasMap);
286  $classLoader->injectClassAliasMap($classAliasMap);
287  spl_autoload_register(array($classLoader, 'loadClass'), TRUE, FALSE);
288  return $this;
289  }
290 
297  public function unregisterClassLoader() {
298  $currentClassLoader = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassLoader');
299  spl_autoload_unregister(array($currentClassLoader, 'loadClass'));
300  return $this;
301  }
302 
309  public function initializeClassLoaderCaches() {
311  $classLoader = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassLoader');
312  $classLoader->injectCoreCache($this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core'));
313  $classLoader->injectClassesCache($this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_classes'));
314  return $this;
315  }
316 
325  public function initializePackageManagement($packageManagerClassName) {
327  $packageManager = new $packageManagerClassName();
328  $this->setEarlyInstance('TYPO3\\Flow\\Package\\PackageManager', $packageManager);
330  $packageManager->injectClassLoader($this->getEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassLoader'));
331  $packageManager->injectCoreCache($this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core'));
332  $packageManager->injectDependencyResolver(Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\DependencyResolver'));
333  $packageManager->initialize($this);
334  Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Package\\PackageManager', $packageManager);
335  return $this;
336  }
337 
344  protected function initializeRuntimeActivatedPackagesFromConfiguration() {
345  if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
347  $packageManager = $this->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManager');
348  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'] as $runtimeAddedPackageKey) {
349  $packageManager->activatePackageDuringRuntime($runtimeAddedPackageKey);
350  }
351  }
352  return $this;
353  }
354 
362  public function loadTypo3LoadedExtAndExtLocalconf($allowCaching = TRUE) {
363  $this->loadAdditionalConfigurationFromExtensions($allowCaching);
364  return $this;
365  }
366 
375  ->setFinalCachingFrameworkCacheConfiguration()
376  ->defineLoggingAndExceptionConstants()
377  ->unsetReservedGlobalVariables();
378  return $this;
379  }
380 
388  public function checkValidBrowserOrDie() {
389  // Checks for proper browser
390  if (empty($GLOBALS['CLIENT']['BROWSER'])) {
391  throw new \RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
392  }
393  return $this;
394  }
395 
402  public function populateLocalConfiguration() {
403  try {
404  $configurationManager = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
405  } catch(\TYPO3\CMS\Core\Exception $exception) {
406  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
407  $this->setEarlyInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', $configurationManager);
408  }
409  $configurationManager->exportConfiguration();
410  return $this;
411  }
412 
419  public function disableCoreAndClassesCache() {
420  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['backend']
421  = 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend';
422  unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['options']);
423  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_classes']['backend']
424  = 'TYPO3\\CMS\\Core\\Cache\\Backend\\TransientMemoryBackend';
425  unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_classes']['options']);
426  return $this;
427  }
428 
434  protected function defineDatabaseConstants() {
435  define('TYPO3_db', $GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
436  define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
437  define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
438  define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
439  define('TYPO3_extTableDef_script',
440  isset($GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript'])
441  ? $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']
442  : 'extTables.php');
443  return $this;
444  }
445 
451  protected function defineUserAgentConstant() {
452  define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
453  return $this;
454  }
455 
461  protected function registerExtDirectComponents() {
462  if (TYPO3_MODE === 'BE') {
463  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.DataProvider', 'TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeDataProvider', 'web', 'user,group');
464  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.Commands', 'TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeCommands', 'web', 'user,group');
465  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.Components.PageTree.ContextMenuDataProvider', 'TYPO3\\CMS\\Backend\\ContextMenu\\Pagetree\\Extdirect\\ContextMenuConfiguration', 'web', 'user,group');
466  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.LiveSearchActions.ExtDirect', 'TYPO3\\CMS\\Backend\\Search\\LiveSearch\\ExtDirect\\LiveSearchDataProvider', 'web_list', 'user,group');
467  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.BackendUserSettings.ExtDirect', 'TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
468  if (Utility\ExtensionManagementUtility::isLoaded('context_help')) {
469  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.CSH.ExtDirect', 'TYPO3\\CMS\\ContextHelp\\ExtDirect\\ContextHelpDataProvider');
470  }
471  Utility\ExtensionManagementUtility::registerExtDirectComponent('TYPO3.ExtDirectStateProvider.ExtDirect', 'TYPO3\\CMS\\Backend\\InterfaceState\\ExtDirect\\DataProvider');
473  'TYPO3.Components.DragAndDrop.CommandController',
474  Utility\ExtensionManagementUtility::extPath('backend') . 'Classes/View/PageLayout/Extdirect/ExtdirectPageCommands.php:TYPO3\\CMS\\Backend\\View\\PageLayout\\ExtDirect\\ExtdirectPageCommands', 'web', 'user,group'
475  );
476  }
477  return $this;
478  }
479 
486  public function initializeCachingFramework() {
487  $this->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework());
488  // @deprecated since 6.2 will be removed in two versions
489  $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheManager');
490  $GLOBALS['typo3CacheFactory'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheFactory');
491  return $this;
492  }
493 
500  protected function transferDeprecatedCurlSettings() {
501  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) && empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'])) {
502  $curlProxy = rtrim(preg_replace('#^https?://#', '', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']), '/');
503  $proxyParts = Utility\GeneralUtility::revExplode(':', $curlProxy, 2);
504  $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
505  $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
506  }
507  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) && empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'])) {
508  $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
509  $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
510  $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
511  }
512  if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse']) {
513  $GLOBALS['TYPO3_CONF_VARS']['HTTP']['adapter'] = 'curl';
514  }
515  return $this;
516  }
517 
523  protected function setCacheHashOptions() {
524  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
525  'cachedParametersWhiteList' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
526  'excludedParameters' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
527  'requireCacheHashPresenceParameters' => Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE),
528  'includePageId' => $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashIncludePageId']
529  );
530  if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
531  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
532  } else {
533  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
534  }
535  return $this;
536  }
537 
543  protected function setDefaultTimezone() {
544  $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
545  if (empty($timeZone)) {
546  // Time zone from the server environment (TZ env or OS query)
547  $defaultTimeZone = @date_default_timezone_get();
548  if ($defaultTimeZone !== '') {
549  $timeZone = $defaultTimeZone;
550  } else {
551  $timeZone = 'UTC';
552  }
553  }
554  // Set default to avoid E_WARNINGs with PHP > 5.3
555  date_default_timezone_set($timeZone);
556  return $this;
557  }
558 
564  protected function initializeL10nLocales() {
565  \TYPO3\CMS\Core\Localization\Locales::initialize();
566  return $this;
567  }
568 
577  if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
578  $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
579  }
580  return $this;
581  }
582 
591  protected function registerGlobalDebugFunctions() {
592  require_once('GlobalDebugFunctions.php');
593  return $this;
594  }
595 
602  protected function registerSwiftMailer() {
603  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] =
604  'TYPO3\\CMS\\Core\\Mail\\SwiftMailerAdapter';
605  return $this;
606  }
607 
613  protected function configureExceptionHandling() {
614  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
615  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
616  $doesIpMatch = Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
617  $displayErrors = (int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'];
618  // Turn error logging on/off.
619  if ($displayErrors !== -1) {
620  // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
621  if ($displayErrors === 2) {
622  $displayErrors = (int)$doesIpMatch;
623  }
624  if ($displayErrors === 0) {
625  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
626  }
627  if ($displayErrors === 1) {
628  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
629  define('TYPO3_ERRORHANDLER_MODE', 'debug');
630  }
631  @ini_set('display_errors', $displayErrors);
632  } elseif ($doesIpMatch) {
633  // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
634  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
635  }
636  return $this;
637  }
638 
645  protected function setMemoryLimit() {
646  if ((int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit'] > 16) {
647  @ini_set('memory_limit', ((int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit'] . 'm'));
648  }
649  return $this;
650  }
651 
658  protected function defineTypo3RequestTypes() {
659  define('TYPO3_REQUESTTYPE_FE', 1);
660  define('TYPO3_REQUESTTYPE_BE', 2);
661  define('TYPO3_REQUESTTYPE_CLI', 4);
662  define('TYPO3_REQUESTTYPE_AJAX', 8);
663  define('TYPO3_REQUESTTYPE_INSTALL', 16);
664  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));
665  return $this;
666  }
667 
677  protected function loadAdditionalConfigurationFromExtensions($allowCaching = TRUE) {
678  Utility\ExtensionManagementUtility::loadExtLocalconf($allowCaching);
679  return $this;
680  }
681 
690  protected function initializeExceptionHandling() {
691  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'])) {
692  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'])) {
693  if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== $this->activeErrorHandlerClassName) {
694  $this->activeErrorHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'];
695  // Register an error handler for the given errorHandlerErrors
696  $errorHandler = Utility\GeneralUtility::makeInstance($this->activeErrorHandlerClassName, $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']);
697  // Set errors which will be converted in an exception
698  $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
699  }
700  } elseif (!empty($this->activeErrorHandlerClassName)) {
701  // Restore error handler in case extensions have unset the configuration in ext_localconf.php
702  restore_error_handler();
703  }
704  if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== $this->activeExceptionHandlerClassName) {
705  $this->activeExceptionHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'];
706  // Registering the exception handler is done in the constructor
707  Utility\GeneralUtility::makeInstance($this->activeExceptionHandlerClassName);
708  }
709  } elseif (!empty($this->activeExceptionHandlerClassName)) {
710  // Restore exception handler in case extensions have unset the configuration in ext_localconf.php
711  restore_exception_handler();
712  }
713  return $this;
714  }
715 
723  $this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
724  return $this;
725  }
726 
732  protected function defineLoggingAndExceptionConstants() {
733  define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
734  define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
735  define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
736  return $this;
737  }
738 
745  protected function unsetReservedGlobalVariables() {
746  unset($GLOBALS['PAGES_TYPES']);
747  unset($GLOBALS['TCA']);
748  unset($GLOBALS['TBE_MODULES']);
749  unset($GLOBALS['TBE_STYLES']);
750  unset($GLOBALS['FILEICONS']);
751  // Those set in init.php:
752  unset($GLOBALS['WEBMOUNTS']);
753  unset($GLOBALS['BE_USER']);
754  // Those set otherwise:
755  unset($GLOBALS['TBE_MODULES_EXT']);
756  unset($GLOBALS['TCA_DESCR']);
757  unset($GLOBALS['LOCAL_LANG']);
758  unset($GLOBALS['TYPO3_AJAX']);
759  return $this;
760  }
761 
768  public function initializeTypo3DbGlobal() {
770  $databaseConnection = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
771  $databaseConnection->setDatabaseName(TYPO3_db);
772  $databaseConnection->setDatabaseUsername(TYPO3_db_username);
773  $databaseConnection->setDatabasePassword(TYPO3_db_password);
774 
775  $databaseHost = TYPO3_db_host;
776  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])) {
777  $databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
778  } elseif (strpos($databaseHost, ':') > 0) {
779  // @TODO: Find a way to handle this case in the install tool and drop this
780  list($databaseHost, $databasePort) = explode(':', $databaseHost);
781  $databaseConnection->setDatabasePort($databasePort);
782  }
783  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])) {
784  $databaseConnection->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
785  }
786  $databaseConnection->setDatabaseHost($databaseHost);
787 
788  $databaseConnection->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
789 
790  if (
791  isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect'])
792  && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']
793  ) {
794  $databaseConnection->setPersistentDatabaseConnection(TRUE);
795  }
796 
797  $isDatabaseHostLocalHost = $databaseHost === 'localhost' || $databaseHost === '127.0.0.1' || $databaseHost === '::1';
798  if (
799  isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress'])
800  && $GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress']
801  && !$isDatabaseHostLocalHost
802  ) {
803  $databaseConnection->setConnectionCompression(TRUE);
804  }
805 
806  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'])) {
808  LF,
809  str_replace('\' . LF . \'', LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']),
810  TRUE
811  );
812  $databaseConnection->setInitializeCommandsAfterConnect($commandsAfterConnect);
813  }
814 
815  $GLOBALS['TYPO3_DB'] = $databaseConnection;
816  // $GLOBALS['TYPO3_DB'] needs to be defined first in order to work for DBAL
817  $GLOBALS['TYPO3_DB']->initialize();
818 
819  return $this;
820  }
821 
831  if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
832  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);
833  }
834  if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
835  if (TYPO3_PROCEED_IF_NO_USER === 2) {
836 
837  } else {
838  $fileContent = Utility\GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
839  if ($fileContent) {
840  header('Location: ' . $fileContent);
841  } else {
842  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);
843  }
844  die;
845  }
846  }
847  return $this;
848  }
849 
858  public function checkBackendIpOrDie() {
859  if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
860  if (!Utility\GeneralUtility::cmpIP(Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
861  throw new \RuntimeException('TYPO3 Backend access denied: The IP address of your client does not match the list of allowed IP addresses.', 1389265900);
862  }
863  }
864  return $this;
865  }
866 
876  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) {
877  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']) {
878  $sslPortSuffix = ':' . (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'];
879  } else {
880  $sslPortSuffix = '';
881  }
882  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] === 3) {
883  $requestStr = substr(Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
884  if ($requestStr === 'index.php' && !Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
885  list(, $url) = explode('://', Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 2);
886  list($server, $address) = explode('/', $url, 2);
887  header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
888  die;
889  }
890  } elseif (!Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
891  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] === 2) {
892  list(, $url) = explode('://', Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
893  list($server, $address) = explode('/', $url, 2);
894  header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
895  die;
896  } else {
897  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);
898  }
899  }
900  }
901  return $this;
902  }
903 
917  public function loadCachedTca() {
918  $cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
920  $codeCache = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core');
921  if ($codeCache->has($cacheIdentifier)) {
922  // substr is necessary, because the php frontend wraps php code around the cache value
923  $GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
924  } else {
925  $this->loadExtensionTables(TRUE);
926  $codeCache->set($cacheIdentifier, serialize($GLOBALS['TCA']));
927  }
928  return $this;
929  }
930 
943  public function loadExtensionTables($allowCaching = TRUE) {
944  Utility\ExtensionManagementUtility::loadBaseTca($allowCaching);
945  Utility\ExtensionManagementUtility::loadExtTables($allowCaching);
947  $this->runExtTablesPostProcessingHooks();
948  return $this;
949  }
950 
965  protected function executeExtTablesAdditionalFile() {
966  // It is discouraged to use those global variables directly, but we
967  // can not prohibit this without breaking backwards compatibility
968  global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
969  global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
970  global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
971  global $_EXTKEY;
972  // Load additional ext tables script if the file exists
973  $extTablesFile = PATH_typo3conf . TYPO3_extTableDef_script;
974  if (file_exists($extTablesFile) && is_file($extTablesFile)) {
975  include $extTablesFile;
976  }
977  }
978 
985  protected function runExtTablesPostProcessingHooks() {
986  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
987  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
989  $hookObject = Utility\GeneralUtility::getUserObj($classReference);
990  if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
991  throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface', 1320585902);
992  }
993  $hookObject->processData();
994  }
995  }
996  }
997 
1004  public function initializeSpriteManager() {
1005  \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
1006  return $this;
1007  }
1008 
1015  public function initializeBackendUser() {
1017  $backendUser = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
1018  $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
1019  $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
1020  $backendUser->auth_timeout_field = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'];
1021  $backendUser->OS = TYPO3_OS;
1022  if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
1023  $backendUser->dontSetCookie = TRUE;
1024  }
1025  // The global must be available very early, because methods below
1026  // might trigger code which relies on it. See: #45625
1027  $GLOBALS['BE_USER'] = $backendUser;
1028  $backendUser->start();
1029  return $this;
1030  }
1031 
1039  $GLOBALS['BE_USER']->checkCLIuser();
1040  $GLOBALS['BE_USER']->backendCheckLogin();
1041  return $this;
1042  }
1043 
1050  public function initializeBackendUserMounts() {
1051  // Includes deleted mount pages as well! @TODO: Figure out why ...
1052  $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
1053  return $this;
1054  }
1055 
1062  public function initializeLanguageObject() {
1064  $GLOBALS['LANG'] = Utility\GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService');
1065  $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
1066  return $this;
1067  }
1068 
1076  ob_clean();
1077  return $this;
1078  }
1079 
1086  public function initializeOutputCompression() {
1087  if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
1088  if (Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
1089  @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
1090  }
1091  ob_start('ob_gzhandler');
1092  }
1093  return $this;
1094  }
1095 
1102  public function sendHttpHeaders() {
1103  if (!empty($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers']) && is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers'])) {
1104  foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers'] as $header) {
1105  header($header);
1106  }
1107  }
1108  return $this;
1109  }
1110 
1119  public function shutdown() {
1120  return $this;
1121  }
1122 
1130  public function initializeBackendTemplate() {
1131  $GLOBALS['TBE_TEMPLATE'] = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
1132  return $this;
1133  }
1134 }
loadAdditionalConfigurationFromExtensions($allowCaching=TRUE)
Definition: Bootstrap.php:677
__construct($applicationContext)
Definition: Bootstrap.php:79
setEarlyInstance($objectName, $instance)
Definition: Bootstrap.php:206
$TYPO3_CONF_VARS['SYS']['contentTable']
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
$TCA['tx_irretutorial_1ncsv_hotel']
static setPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
const TYPO3_MODE
Definition: init.php:40
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
loadConfigurationAndInitialize($allowCaching=TRUE, $packageManagerClassName='TYPO3\\CMS\\Core\\Package\\PackageManager')
Definition: Bootstrap.php:242
const TYPO3_enterInstallScript
Definition: Install.php:97
die
Definition: index.php:6
loadTypo3LoadedExtAndExtLocalconf($allowCaching=TRUE)
Definition: Bootstrap.php:362
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
const TYPO3_PROCEED_IF_NO_USER
Definition: index.php:20
baseSetup($relativePathPart='')
Definition: Bootstrap.php:152
static registerExtDirectComponent($endpointName, $callbackClass, $moduleName=NULL, $accessLevel=NULL)
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)
redirectToInstallerIfEssentialConfigurationDoesNotExist($pathUpToDocumentRoot='')
Definition: Bootstrap.php:185
static presetApplicationContext(\TYPO3\CMS\Core\Core\ApplicationContext $applicationContext)
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static revExplode($delimiter, $string, $count=0)
static initializeCachingFramework()
Definition: Cache.php:46
loadExtensionTables($allowCaching=TRUE)
Definition: Bootstrap.php:943