TYPO3 CMS  TYPO3_7-6
Bootstrap.php
Go to the documentation of this file.
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 
24 
36 class Bootstrap
37 {
41  protected static $instance = null;
42 
48  protected $requestId;
49 
56 
60  protected $earlyInstances = [];
61 
65  protected $installToolPath;
66 
71  protected $availableRequestHandlers = [];
72 
78  protected $response;
79 
83  protected static $usesComposerClassLoading = false;
84 
91  protected function __construct($applicationContext)
92  {
93  $this->requestId = substr(md5(uniqid('', true)), 0, 13);
94  $this->applicationContext = new ApplicationContext($applicationContext);
95  }
96 
100  public static function usesComposerClassLoading()
101  {
102  return self::$usesComposerClassLoading;
103  }
104 
108  protected function __clone()
109  {
110  }
111 
118  public static function getInstance()
119  {
120  if (is_null(static::$instance)) {
121  $applicationContext = getenv('TYPO3_CONTEXT') ?: (getenv('REDIRECT_TYPO3_CONTEXT') ?: 'Production');
122  self::$instance = new static($applicationContext);
123  }
124  return static::$instance;
125  }
126 
133  public function getRequestId()
134  {
135  return $this->requestId;
136  }
137 
145  public function getApplicationContext()
146  {
148  }
149 
157  public function startOutputBuffering()
158  {
159  ob_start();
160  return $this;
161  }
162 
171  public function configure()
172  {
173  $this->startOutputBuffering()
174  ->loadConfigurationAndInitialize()
175  ->loadTypo3LoadedExtAndExtLocalconf(true)
176  ->setFinalCachingFrameworkCacheConfiguration()
177  ->defineLoggingAndExceptionConstants()
178  ->unsetReservedGlobalVariables()
179  ->initializeTypo3DbGlobal();
180  if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
181  throw new \RuntimeException(
182  'TYPO3 Encryption is empty. $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'encryptionKey\'] needs to be set for TYPO3 to work securely',
183  1502987245
184  );
185  }
186  return $this;
187  }
188 
199  public function baseSetup($relativePathPart = '')
200  {
201  SystemEnvironmentBuilder::run($relativePathPart);
202  if (!self::$usesComposerClassLoading && ClassLoadingInformation::isClassLoadingInformationAvailable()) {
204  }
205  GeneralUtility::presetApplicationContext($this->applicationContext);
206  return $this;
207  }
208 
216  public function initializeClassLoader($classLoader)
217  {
218  $this->setEarlyInstance(\Composer\Autoload\ClassLoader::class, $classLoader);
219  if (defined('TYPO3_COMPOSER_MODE') && TYPO3_COMPOSER_MODE) {
220  self::$usesComposerClassLoading = true;
221  }
222  return $this;
223  }
224 
233  {
234  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
235  $this->setEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class, $configurationManager);
236  return file_exists($configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
237  }
238 
244  public function redirectToInstallTool($relativePathPart = '')
245  {
246  $backPathToSiteRoot = str_repeat('../', count(explode('/', $relativePathPart)) - 1);
247  header('Location: ' . $backPathToSiteRoot . 'typo3/sysext/install/Start/Install.php');
248  die;
249  }
250 
258  public function registerRequestHandlerImplementation($requestHandler)
259  {
260  $this->availableRequestHandlers[] = $requestHandler;
261  return $this;
262  }
263 
274  protected function resolveRequestHandler($request)
275  {
276  $suitableRequestHandlers = [];
277  foreach ($this->availableRequestHandlers as $requestHandlerClassName) {
279  $requestHandler = GeneralUtility::makeInstance($requestHandlerClassName, $this);
280  if ($requestHandler->canHandleRequest($request)) {
281  $priority = $requestHandler->getPriority();
282  if (isset($suitableRequestHandlers[$priority])) {
283  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);
284  }
285  $suitableRequestHandlers[$priority] = $requestHandler;
286  }
287  }
288  if (empty($suitableRequestHandlers)) {
289  throw new \TYPO3\CMS\Core\Exception('No suitable request handler found.', 1225418233);
290  }
291  ksort($suitableRequestHandlers);
292  return array_pop($suitableRequestHandlers);
293  }
294 
304  public function handleRequest($request)
305  {
306 
307  // Resolve request handler that were registered based on the Application
308  $requestHandler = $this->resolveRequestHandler($request);
309 
310  // Execute the command which returns a Response object or NULL
311  $this->response = $requestHandler->handleRequest($request);
312  return $this;
313  }
314 
320  protected function sendResponse()
321  {
322  if ($this->response instanceof \Psr\Http\Message\ResponseInterface) {
323  if (!headers_sent()) {
324  // If the response code was not changed by legacy code (still is 200)
325  // then allow the PSR-7 response object to explicitly set it.
326  // Otherwise let legacy code take precedence.
327  // This code path can be deprecated once we expose the response object to third party code
328  if (http_response_code() === 200) {
329  header('HTTP/' . $this->response->getProtocolVersion() . ' ' . $this->response->getStatusCode() . ' ' . $this->response->getReasonPhrase());
330  }
331 
332  foreach ($this->response->getHeaders() as $name => $values) {
333  header($name . ': ' . implode(', ', $values));
334  }
335  }
336  echo $this->response->getBody()->__toString();
337  }
338  return $this;
339  }
340 
351  public function setEarlyInstance($objectName, $instance)
352  {
353  $this->earlyInstances[$objectName] = $instance;
354  }
355 
364  public function getEarlyInstance($objectName)
365  {
366  if (!isset($this->earlyInstances[$objectName])) {
367  throw new \TYPO3\CMS\Core\Exception('Unknown early instance "' . $objectName . '"', 1365167380);
368  }
369  return $this->earlyInstances[$objectName];
370  }
371 
378  public function getEarlyInstances()
379  {
380  return $this->earlyInstances;
381  }
382 
392  public function loadConfigurationAndInitialize($allowCaching = true, $packageManagerClassName = \TYPO3\CMS\Core\Package\PackageManager::class)
393  {
395  ->initializeErrorHandling()
396  ->initializeIO();
397  if (!$allowCaching) {
398  $this->disableCoreCache();
399  }
401  ->initializePackageManagement($packageManagerClassName)
402  ->initializeRuntimeActivatedPackagesFromConfiguration()
403  ->defineDatabaseConstants()
404  ->defineUserAgentConstant()
405  ->registerExtDirectComponents()
406  ->setCacheHashOptions()
407  ->setDefaultTimezone()
408  ->initializeL10nLocales()
409  ->convertPageNotFoundHandlingToBoolean()
410  ->setMemoryLimit()
411  ->defineTypo3RequestTypes();
412  if ($allowCaching) {
414  }
415  return $this;
416  }
417 
426  public function initializePackageManagement($packageManagerClassName)
427  {
429  $packageManager = new $packageManagerClassName();
430  $this->setEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
432  $packageManager->injectCoreCache($this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core'));
433  $dependencyResolver = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\DependencyResolver::class);
434  $dependencyResolver->injectDependencyOrderingService(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Service\DependencyOrderingService::class));
435  $packageManager->injectDependencyResolver($dependencyResolver);
436  $packageManager->initialize($this);
437  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
438  return $this;
439  }
440 
448  {
449  if (!self::$usesComposerClassLoading && !ClassLoadingInformation::isClassLoadingInformationAvailable()) {
450  ClassLoadingInformation::dumpClassLoadingInformation();
452  }
453  return $this;
454  }
455 
462  protected function initializeRuntimeActivatedPackagesFromConfiguration()
463  {
464  if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
466  $packageManager = $this->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
467  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'] as $runtimeAddedPackageKey) {
468  $packageManager->activatePackageDuringRuntime($runtimeAddedPackageKey);
469  }
470  }
471  return $this;
472  }
473 
481  public function loadTypo3LoadedExtAndExtLocalconf($allowCaching = true)
482  {
483  ExtensionManagementUtility::loadExtLocalconf($allowCaching);
484  return $this;
485  }
486 
494  public function populateLocalConfiguration()
495  {
496  try {
497  $configurationManager = $this->getEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
498  } catch (\TYPO3\CMS\Core\Exception $exception) {
499  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
500  $this->setEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class, $configurationManager);
501  }
502  $configurationManager->exportConfiguration();
503  return $this;
504  }
505 
512  public function disableCoreCache()
513  {
514  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['backend']
515  = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class;
516  unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['options']);
517  return $this;
518  }
519 
525  protected function defineDatabaseConstants()
526  {
527  define('TYPO3_db', $GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
528  define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
529  define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
530  define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
531  // Constant TYPO3_extTableDef_script is deprecated since TYPO3 CMS 7 and will be dropped with TYPO3 CMS 8
532  define('TYPO3_extTableDef_script',
533  isset($GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript'])
534  ? $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']
535  : 'extTables.php');
536  return $this;
537  }
538 
544  protected function defineUserAgentConstant()
545  {
546  define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
547  return $this;
548  }
549 
555  protected function registerExtDirectComponents()
556  {
557  if (TYPO3_MODE === 'BE') {
559  'TYPO3.Components.PageTree.DataProvider',
560  \TYPO3\CMS\Backend\Tree\Pagetree\ExtdirectTreeDataProvider::class
561  );
563  'TYPO3.Components.PageTree.Commands',
564  \TYPO3\CMS\Backend\Tree\Pagetree\ExtdirectTreeCommands::class
565  );
567  'TYPO3.Components.PageTree.ContextMenuDataProvider',
568  \TYPO3\CMS\Backend\ContextMenu\Pagetree\Extdirect\ContextMenuConfiguration::class
569  );
571  'TYPO3.ExtDirectStateProvider.ExtDirect',
572  \TYPO3\CMS\Backend\InterfaceState\ExtDirect\DataProvider::class
573  );
575  'TYPO3.Components.DragAndDrop.CommandController',
576  ExtensionManagementUtility::extPath('backend') . 'Classes/View/PageLayout/Extdirect/ExtdirectPageCommands.php:' . \TYPO3\CMS\Backend\View\PageLayout\ExtDirect\ExtdirectPageCommands::class
577  );
578  }
579  return $this;
580  }
581 
589  public function initializeCachingFramework()
590  {
591  $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
592  $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
593  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
594 
595  $cacheFactory = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager);
596  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, $cacheFactory);
597 
598  $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
599  return $this;
600  }
601 
607  protected function setCacheHashOptions()
608  {
609  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = [
610  'cachedParametersWhiteList' => GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], true),
611  'excludedParameters' => GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], true),
612  'requireCacheHashPresenceParameters' => GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], true),
613  'includePageId' => $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashIncludePageId']
614  ];
615  if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
616  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = true;
617  } else {
618  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], true);
619  }
620  return $this;
621  }
622 
628  protected function setDefaultTimezone()
629  {
630  $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
631  if (empty($timeZone)) {
632  // Time zone from the server environment (TZ env or OS query)
633  $defaultTimeZone = @date_default_timezone_get();
634  if ($defaultTimeZone !== '') {
635  $timeZone = $defaultTimeZone;
636  } else {
637  $timeZone = 'UTC';
638  }
639  }
640  // Set default to avoid E_WARNINGs with PHP > 5.3
641  date_default_timezone_set($timeZone);
642  return $this;
643  }
644 
650  protected function initializeL10nLocales()
651  {
652  \TYPO3\CMS\Core\Localization\Locales::initialize();
653  return $this;
654  }
655 
664  {
665  if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
666  $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = true;
667  }
668  return $this;
669  }
670 
677  protected function initializeErrorHandling()
678  {
679  $productionExceptionHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
680  $debugExceptionHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
681 
682  $errorHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'];
683  $errorHandlerErrors = $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors'];
684  $exceptionalErrors = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
685 
686  $displayErrorsSetting = (int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'];
687  switch ($displayErrorsSetting) {
688  case 2:
689  GeneralUtility::deprecationLog('The option "$TYPO3_CONF_VARS[SYS][displayErrors]" is set to "2" which is deprecated as of TYPO3 CMS 7, and will be removed with TYPO3 CMS 8. Please change the value to "-1"');
690  // intentionally fall through
691  case -1:
692  $ipMatchesDevelopmentSystem = GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
693  $exceptionHandlerClassName = $ipMatchesDevelopmentSystem ? $debugExceptionHandlerClassName : $productionExceptionHandlerClassName;
694  $displayErrors = $ipMatchesDevelopmentSystem ? 1 : 0;
695  $exceptionalErrors = $ipMatchesDevelopmentSystem ? $exceptionalErrors : 0;
696  break;
697  case 0:
698  $exceptionHandlerClassName = $productionExceptionHandlerClassName;
699  $displayErrors = 0;
700  break;
701  case 1:
702  $exceptionHandlerClassName = $debugExceptionHandlerClassName;
703  $displayErrors = 1;
704  break;
705  default:
706  // Throw exception if an invalid option is set.
707  throw new \RuntimeException('The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".');
708  }
709  @ini_set('display_errors', $displayErrors);
710 
711  if (!empty($errorHandlerClassName)) {
712  // Register an error handler for the given errorHandlerError
713  $errorHandler = GeneralUtility::makeInstance($errorHandlerClassName, $errorHandlerErrors);
714  $errorHandler->setExceptionalErrors($exceptionalErrors);
715  if (is_callable([$errorHandler, 'setDebugMode'])) {
716  $errorHandler->setDebugMode($displayErrors === 1);
717  }
718  }
719  if (!empty($exceptionHandlerClassName)) {
720  // Registering the exception handler is done in the constructor
721  GeneralUtility::makeInstance($exceptionHandlerClassName);
722  }
723  return $this;
724  }
725 
729  protected function initializeIO()
730  {
731  if (in_array('phar', stream_get_wrappers())) {
732  // destroy and re-initialize PharStreamWrapper for TYPO3 core
733  Manager::destroy();
734  Manager::initialize(
735  (new Behavior())
736  ->withAssertion(new PharStreamWrapperInterceptor())
737  );
738 
739  stream_wrapper_unregister('phar');
740  stream_wrapper_register('phar', PharStreamWrapper::class);
741  }
742  }
743 
750  protected function setMemoryLimit()
751  {
752  if ((int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit'] > 16) {
753  @ini_set('memory_limit', ((int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit'] . 'm'));
754  }
755  return $this;
756  }
757 
764  public function defineTypo3RequestTypes()
765  {
766  define('TYPO3_REQUESTTYPE_FE', 1);
767  define('TYPO3_REQUESTTYPE_BE', 2);
768  define('TYPO3_REQUESTTYPE_CLI', 4);
769  define('TYPO3_REQUESTTYPE_AJAX', 8);
770  define('TYPO3_REQUESTTYPE_INSTALL', 16);
771  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));
772  return $this;
773  }
774 
783  {
784  $this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
785  return $this;
786  }
787 
795  {
796  define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
797  define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
798  define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
799  return $this;
800  }
801 
810  {
811  unset($GLOBALS['PAGES_TYPES']);
812  unset($GLOBALS['TCA']);
813  unset($GLOBALS['TBE_MODULES']);
814  unset($GLOBALS['TBE_STYLES']);
815  unset($GLOBALS['BE_USER']);
816  // Those set otherwise:
817  unset($GLOBALS['TBE_MODULES_EXT']);
818  unset($GLOBALS['TCA_DESCR']);
819  unset($GLOBALS['LOCAL_LANG']);
820  unset($GLOBALS['TYPO3_AJAX']);
821  return $this;
822  }
823 
830  public function initializeTypo3DbGlobal()
831  {
833  $databaseConnection = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
834  $databaseConnection->setDatabaseName(TYPO3_db);
835  $databaseConnection->setDatabaseUsername(TYPO3_db_username);
836  $databaseConnection->setDatabasePassword(TYPO3_db_password);
837 
838  $databaseHost = TYPO3_db_host;
839  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['port'])) {
840  $databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
841  } elseif (strpos($databaseHost, ':') > 0) {
842  // @TODO: Find a way to handle this case in the install tool and drop this
843  list($databaseHost, $databasePort) = explode(':', $databaseHost);
844  $databaseConnection->setDatabasePort($databasePort);
845  }
846  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])) {
847  $databaseConnection->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
848  }
849  $databaseConnection->setDatabaseHost($databaseHost);
850 
851  $databaseConnection->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
852 
853  if (
854  isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect'])
855  && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']
856  ) {
857  $databaseConnection->setPersistentDatabaseConnection(true);
858  }
859 
860  $isDatabaseHostLocalHost = $databaseHost === 'localhost' || $databaseHost === '127.0.0.1' || $databaseHost === '::1';
861  if (
862  isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress'])
863  && $GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress']
864  && !$isDatabaseHostLocalHost
865  ) {
866  $databaseConnection->setConnectionCompression(true);
867  }
868 
869  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'])) {
870  $commandsAfterConnect = GeneralUtility::trimExplode(
871  LF,
872  str_replace('\' . LF . \'', LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']),
873  true
874  );
875  $databaseConnection->setInitializeCommandsAfterConnect($commandsAfterConnect);
876  }
877 
878  $GLOBALS['TYPO3_DB'] = $databaseConnection;
879  // $GLOBALS['TYPO3_DB'] needs to be defined first in order to work for DBAL
880  $GLOBALS['TYPO3_DB']->initialize();
881 
882  return $this;
883  }
884 
894  public function checkLockedBackendAndRedirectOrDie($forceProceeding = false)
895  {
896  if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
897  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);
898  }
899  if (@is_file(PATH_typo3conf . 'LOCK_BACKEND') && $forceProceeding === false) {
900  $fileContent = GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
901  if ($fileContent) {
902  header('Location: ' . $fileContent);
903  } else {
904  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);
905  }
906  die;
907  }
908  return $this;
909  }
910 
919  public function checkBackendIpOrDie()
920  {
921  if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
922  if (!GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
923  throw new \RuntimeException('TYPO3 Backend access denied: The IP address of your client does not match the list of allowed IP addresses.', 1389265900);
924  }
925  }
926  return $this;
927  }
928 
938  {
939  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) {
940  if (!GeneralUtility::getIndpEnv('TYPO3_SSL')) {
941  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] === 2) {
942  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']) {
943  $sslPortSuffix = ':' . (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'];
944  } else {
945  $sslPortSuffix = '';
946  }
947  list(, $url) = explode('://', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
948  list($server, $address) = explode('/', $url, 2);
949  header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
950  die;
951  } else {
952  throw new \RuntimeException('TYPO3 Backend not accessed via SSL: TYPO3 Backend is configured to only be accessible through SSL. Change the URL in your browser and try again.', 1389265726);
953  }
954  }
955  }
956  return $this;
957  }
958 
972  public function loadCachedTca()
973  {
974  $cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
976  $codeCache = $this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
977  if ($codeCache->has($cacheIdentifier)) {
978  // substr is necessary, because the php frontend wraps php code around the cache value
979  $GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
980  } else {
981  $this->loadExtensionTables(true);
982  $codeCache->set($cacheIdentifier, serialize($GLOBALS['TCA']));
983  }
984  return $this;
985  }
986 
999  public function loadExtensionTables($allowCaching = true)
1000  {
1001  ExtensionManagementUtility::loadBaseTca($allowCaching);
1002  ExtensionManagementUtility::loadExtTables($allowCaching);
1004  $this->runExtTablesPostProcessingHooks();
1005  return $this;
1006  }
1007 
1020  protected function executeExtTablesAdditionalFile()
1021  {
1022  // It is discouraged to use those global variables directly, but we
1023  // can not prohibit this without breaking backwards compatibility
1024  global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
1025  global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
1026  global $PAGES_TYPES, $TBE_STYLES;
1027  global $_EXTKEY;
1028  // Load additional ext tables script if the file exists
1029  $extTablesFile = PATH_typo3conf . TYPO3_extTableDef_script;
1030  if (file_exists($extTablesFile) && is_file($extTablesFile)) {
1032  'Using typo3conf/' . TYPO3_extTableDef_script . ' is deprecated and will be removed with TYPO3 CMS 8. Please move your TCA overrides'
1033  . ' to Configuration/TCA/Overrides of your project specific extension, or slot the signal "tcaIsBeingBuilt" for further processing.'
1034  );
1035  include $extTablesFile;
1036  }
1037  }
1038 
1045  protected function runExtTablesPostProcessingHooks()
1046  {
1047  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
1048  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
1050  $hookObject = GeneralUtility::getUserObj($classReference);
1051  if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
1052  throw new \UnexpectedValueException(
1053  '$hookObject "' . $classReference . '" must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface',
1054  1320585902
1055  );
1056  }
1057  $hookObject->processData();
1058  }
1059  }
1060  }
1061 
1069  public function initializeSpriteManager()
1070  {
1071  // This method is deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
1072  // This method does not log a deprecation message, because it is used only in the request handlers
1073  // and would break icons from IconUtility::getSpriteIcon() if we remove it yet.
1074  \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
1075  return $this;
1076  }
1077 
1085  public function initializeBackendRouter()
1086  {
1087  // See if the Routes.php from all active packages have been built together already
1088  $cacheIdentifier = 'BackendRoutesFromPackages_' . sha1((TYPO3_version . PATH_site . 'BackendRoutesFromPackages'));
1089 
1091  $codeCache = $this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
1092  $routesFromPackages = [];
1093  if ($codeCache->has($cacheIdentifier)) {
1094  // substr is necessary, because the php frontend wraps php code around the cache value
1095  $routesFromPackages = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
1096  } else {
1097  // Loop over all packages and check for a Configuration/Backend/Routes.php file
1098  $packageManager = $this->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
1099  $packages = $packageManager->getActivePackages();
1100  foreach ($packages as $package) {
1101  $routesFileNameForPackage = $package->getPackagePath() . 'Configuration/Backend/Routes.php';
1102  if (file_exists($routesFileNameForPackage)) {
1103  $definedRoutesInPackage = require $routesFileNameForPackage;
1104  if (is_array($definedRoutesInPackage)) {
1105  $routesFromPackages = array_merge($routesFromPackages, $definedRoutesInPackage);
1106  }
1107  }
1108  $routesFileNameForPackage = $package->getPackagePath() . 'Configuration/Backend/AjaxRoutes.php';
1109  if (file_exists($routesFileNameForPackage)) {
1110  $definedRoutesInPackage = require $routesFileNameForPackage;
1111  if (is_array($definedRoutesInPackage)) {
1112  foreach ($definedRoutesInPackage as $routeIdentifier => $routeOptions) {
1113  // prefix the route with "ajax_" as "namespace"
1114  $routeOptions['path'] = '/ajax' . $routeOptions['path'];
1115  $routesFromPackages['ajax_' . $routeIdentifier] = $routeOptions;
1116  $routesFromPackages['ajax_' . $routeIdentifier]['ajax'] = true;
1117  }
1118  }
1119  }
1120  }
1121  // Store the data from all packages in the cache
1122  $codeCache->set($cacheIdentifier, serialize($routesFromPackages));
1123  }
1124 
1125  // Build Route objects from the data
1126  $router = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\Router::class);
1127  foreach ($routesFromPackages as $name => $options) {
1128  $path = $options['path'];
1129  unset($options['path']);
1130  $route = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\Route::class, $path, $options);
1131  $router->addRoute($name, $route);
1132  }
1133  return $this;
1134  }
1135 
1142  public function initializeBackendUser()
1143  {
1145  $backendUser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
1146  $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
1147  $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
1148  $backendUser->auth_timeout_field = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'];
1149  if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
1150  $backendUser->dontSetCookie = true;
1151  }
1152  // The global must be available very early, because methods below
1153  // might trigger code which relies on it. See: #45625
1154  $GLOBALS['BE_USER'] = $backendUser;
1155  $backendUser->start();
1156  return $this;
1157  }
1158 
1166  public function initializeBackendAuthentication($proceedIfNoUserIsLoggedIn = false)
1167  {
1168  $GLOBALS['BE_USER']->backendCheckLogin($proceedIfNoUserIsLoggedIn);
1169  return $this;
1170  }
1171 
1178  public function initializeLanguageObject()
1179  {
1181  $GLOBALS['LANG'] = GeneralUtility::makeInstance(\TYPO3\CMS\Lang\LanguageService::class);
1182  $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
1183  return $this;
1184  }
1185 
1193  {
1194  ob_clean();
1195  return $this;
1196  }
1197 
1205  {
1206  if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
1207  if (MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
1208  @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
1209  }
1210  ob_start('ob_gzhandler');
1211  }
1212  return $this;
1213  }
1214 
1221  public function sendHttpHeaders()
1222  {
1223  if (!empty($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers']) && is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers'])) {
1224  foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers'] as $header) {
1225  header($header);
1226  }
1227  }
1228  return $this;
1229  }
1230 
1239  public function shutdown()
1240  {
1241  $this->sendResponse();
1242  return $this;
1243  }
1244 
1252  public function initializeBackendTemplate()
1253  {
1254  $GLOBALS['TBE_TEMPLATE'] = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
1255  return $this;
1256  }
1257 }
__construct($applicationContext)
Definition: Bootstrap.php:91
loadTypo3LoadedExtAndExtLocalconf($allowCaching=true)
Definition: Bootstrap.php:481
loadExtensionTables($allowCaching=true)
Definition: Bootstrap.php:999
setEarlyInstance($objectName, $instance)
Definition: Bootstrap.php:351
registerRequestHandlerImplementation($requestHandler)
Definition: Bootstrap.php:258
static setSingletonInstance($className, SingletonInterface $instance)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
redirectToInstallTool($relativePathPart='')
Definition: Bootstrap.php:244
baseSetup($relativePathPart='')
Definition: Bootstrap.php:199
initializeBackendAuthentication($proceedIfNoUserIsLoggedIn=false)
Definition: Bootstrap.php:1166
initializeClassLoader($classLoader)
Definition: Bootstrap.php:216
static registerExtDirectComponent($endpointName, $callbackClass, $moduleName=null, $accessLevel=null)
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)
static setPackageManager(PackageManager $packageManager)
$TCA['tx_blogexample_domain_model_blog']
Definition: Blog.php:4
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
loadConfigurationAndInitialize($allowCaching=true, $packageManagerClassName=\TYPO3\CMS\Core\Package\PackageManager::class)
Definition: Bootstrap.php:392
checkLockedBackendAndRedirectOrDie($forceProceeding=false)
Definition: Bootstrap.php:894
static presetApplicationContext(ApplicationContext $applicationContext)