TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
core/Classes/Core/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 
20 
32 class Bootstrap
33 {
37  protected static $instance = null;
38 
44  protected $requestId;
45 
52 
56  protected $earlyInstances = [];
57 
61  protected $installToolPath;
62 
67  protected $availableRequestHandlers = [];
68 
74  protected $response;
75 
79  protected static $usesComposerClassLoading = false;
80 
87  protected function __construct($applicationContext)
88  {
89  $this->requestId = substr(md5(uniqid('', true)), 0, 13);
90  $this->applicationContext = new ApplicationContext($applicationContext);
91  }
92 
96  public static function usesComposerClassLoading()
97  {
98  return self::$usesComposerClassLoading;
99  }
100 
104  protected function __clone()
105  {
106  }
107 
114  public static function getInstance()
115  {
116  if (is_null(static::$instance)) {
117  $applicationContext = getenv('TYPO3_CONTEXT') ?: (getenv('REDIRECT_TYPO3_CONTEXT') ?: 'Production');
118  self::$instance = new static($applicationContext);
119  self::$instance->defineTypo3RequestTypes();
120  }
121  return static::$instance;
122  }
123 
130  public function getRequestId()
131  {
132  return $this->requestId;
133  }
134 
142  public function getApplicationContext()
143  {
145  }
146 
154  public function startOutputBuffering()
155  {
156  ob_start();
157  return $this;
158  }
159 
168  public function configure()
169  {
170  $this->startOutputBuffering()
171  ->loadConfigurationAndInitialize()
172  ->loadTypo3LoadedExtAndExtLocalconf(true)
173  ->setFinalCachingFrameworkCacheConfiguration()
174  ->defineLoggingAndExceptionConstants()
175  ->unsetReservedGlobalVariables()
176  ->initializeTypo3DbGlobal();
177 
178  return $this;
179  }
180 
192  public function baseSetup($entryPointLevel = 0)
193  {
194  if (!defined('TYPO3_REQUESTTYPE')) {
195  throw new \RuntimeException('No Request Type was set, TYPO3 does not know in which context it is run.', 1450561838);
196  }
197  SystemEnvironmentBuilder::run($entryPointLevel);
198  if (!self::$usesComposerClassLoading && ClassLoadingInformation::isClassLoadingInformationAvailable()) {
200  }
201  GeneralUtility::presetApplicationContext($this->applicationContext);
202  return $this;
203  }
204 
212  public function initializeClassLoader($classLoader)
213  {
214  $this->setEarlyInstance(\Composer\Autoload\ClassLoader::class, $classLoader);
215  if (defined('TYPO3_COMPOSER_MODE') && TYPO3_COMPOSER_MODE) {
216  self::$usesComposerClassLoading = true;
217  }
218  return $this;
219  }
220 
229  {
230  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
231  $this->setEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class, $configurationManager);
232  return file_exists($configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
233  }
234 
241  public function redirectToInstallTool($entryPointLevel = 0)
242  {
243  $path = TYPO3_mainDir . 'sysext/install/Start/Install.php';
244  if ($entryPointLevel > 0) {
245  $path = str_repeat('../', $entryPointLevel) . $path;
246  }
247  header('Location: ' . $path);
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  // Resolve request handler that were registered based on the Application
307  $requestHandler = $this->resolveRequestHandler($request);
308 
309  // Execute the command which returns a Response object or NULL
310  $this->response = $requestHandler->handleRequest($request);
311  return $this;
312  }
313 
319  protected function sendResponse()
320  {
321  if ($this->response instanceof \Psr\Http\Message\ResponseInterface) {
322  if (!headers_sent()) {
323  foreach ($this->response->getHeaders() as $name => $values) {
324  header($name . ': ' . implode(', ', $values));
325  }
326  // If the response code was not changed by legacy code (still is 200)
327  // then allow the PSR-7 response object to explicitly set it.
328  // Otherwise let legacy code take precedence.
329  // This code path can be deprecated once we expose the response object to third party code
330  if (http_response_code() === 200) {
331  header('HTTP/' . $this->response->getProtocolVersion() . ' ' . $this->response->getStatusCode() . ' ' . $this->response->getReasonPhrase());
332  }
333  }
334  echo $this->response->getBody()->__toString();
335  }
336  return $this;
337  }
338 
349  public function setEarlyInstance($objectName, $instance)
350  {
351  $this->earlyInstances[$objectName] = $instance;
352  }
353 
362  public function getEarlyInstance($objectName)
363  {
364  if (!isset($this->earlyInstances[$objectName])) {
365  throw new \TYPO3\CMS\Core\Exception('Unknown early instance "' . $objectName . '"', 1365167380);
366  }
367  return $this->earlyInstances[$objectName];
368  }
369 
376  public function getEarlyInstances()
377  {
378  return $this->earlyInstances;
379  }
380 
390  public function loadConfigurationAndInitialize($allowCaching = true, $packageManagerClassName = \TYPO3\CMS\Core\Package\PackageManager::class)
391  {
393  ->initializeErrorHandling();
394  if (!$allowCaching) {
395  $this->disableCoreCache();
396  }
398  ->initializePackageManagement($packageManagerClassName)
399  ->initializeRuntimeActivatedPackagesFromConfiguration()
400  ->defineUserAgentConstant()
401  ->registerExtDirectComponents()
402  ->setCacheHashOptions()
403  ->setDefaultTimezone()
404  ->initializeL10nLocales()
405  ->setMemoryLimit();
406  if ($allowCaching) {
408  }
409  return $this;
410  }
411 
420  public function initializePackageManagement($packageManagerClassName)
421  {
423  $packageManager = new $packageManagerClassName();
424  $this->setEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
426  $packageManager->injectCoreCache($this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core'));
427  $dependencyResolver = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\DependencyResolver::class);
428  $dependencyResolver->injectDependencyOrderingService(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Service\DependencyOrderingService::class));
429  $packageManager->injectDependencyResolver($dependencyResolver);
430  $packageManager->initialize();
431  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
432  return $this;
433  }
434 
443  {
444  if (!self::$usesComposerClassLoading && !ClassLoadingInformation::isClassLoadingInformationAvailable()) {
446  ClassLoadingInformation::dumpClassLoadingInformation();
448  }
449  return $this;
450  }
451 
458  protected function initializeRuntimeActivatedPackagesFromConfiguration()
459  {
460  if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
462  $packageManager = $this->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
463  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'] as $runtimeAddedPackageKey) {
464  $packageManager->activatePackageDuringRuntime($runtimeAddedPackageKey);
465  }
466  }
467  return $this;
468  }
469 
477  public function loadTypo3LoadedExtAndExtLocalconf($allowCaching = true)
478  {
479  ExtensionManagementUtility::loadExtLocalconf($allowCaching);
480  return $this;
481  }
482 
490  public function populateLocalConfiguration()
491  {
492  try {
493  $configurationManager = $this->getEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
494  } catch (\TYPO3\CMS\Core\Exception $exception) {
495  $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
496  $this->setEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class, $configurationManager);
497  }
498  $configurationManager->exportConfiguration();
499  return $this;
500  }
501 
508  public function disableCoreCache()
509  {
510  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['backend']
511  = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class;
512  unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_core']['options']);
513  return $this;
514  }
515 
521  protected function defineUserAgentConstant()
522  {
523  define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['headers']['User-Agent']);
524  return $this;
525  }
526 
532  protected function registerExtDirectComponents()
533  {
534  if (TYPO3_MODE === 'BE') {
536  'TYPO3.Components.PageTree.DataProvider',
537  \TYPO3\CMS\Backend\Tree\Pagetree\ExtdirectTreeDataProvider::class
538  );
540  'TYPO3.Components.PageTree.Commands',
541  \TYPO3\CMS\Backend\Tree\Pagetree\ExtdirectTreeCommands::class
542  );
544  'TYPO3.Components.PageTree.ContextMenuDataProvider',
545  \TYPO3\CMS\Backend\ContextMenu\Pagetree\Extdirect\ContextMenuConfiguration::class
546  );
548  'TYPO3.ExtDirectStateProvider.ExtDirect',
549  \TYPO3\CMS\Backend\InterfaceState\ExtDirect\DataProvider::class
550  );
551  }
552  return $this;
553  }
554 
562  public function initializeCachingFramework()
563  {
564  $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
565  $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
566  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
567  $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
568  return $this;
569  }
570 
576  protected function setCacheHashOptions()
577  {
578  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = [
579  'cachedParametersWhiteList' => GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], true),
580  'excludedParameters' => GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], true),
581  'requireCacheHashPresenceParameters' => GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], true),
582  'includePageId' => $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashIncludePageId']
583  ];
584  if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
585  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = true;
586  } else {
587  $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], true);
588  }
589  return $this;
590  }
591 
597  protected function setDefaultTimezone()
598  {
599  $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
600  if (empty($timeZone)) {
601  // Time zone from the server environment (TZ env or OS query)
602  $defaultTimeZone = @date_default_timezone_get();
603  if ($defaultTimeZone !== '') {
604  $timeZone = $defaultTimeZone;
605  } else {
606  $timeZone = 'UTC';
607  }
608  }
609  // Set default to avoid E_WARNINGs with PHP > 5.3
610  date_default_timezone_set($timeZone);
611  return $this;
612  }
613 
619  protected function initializeL10nLocales()
620  {
621  \TYPO3\CMS\Core\Localization\Locales::initialize();
622  return $this;
623  }
624 
631  protected function initializeErrorHandling()
632  {
633  $productionExceptionHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
634  $debugExceptionHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
635 
636  $errorHandlerClassName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'];
637  $errorHandlerErrors = $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors'];
638  $exceptionalErrors = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
639 
640  $displayErrorsSetting = (int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'];
641  switch ($displayErrorsSetting) {
642  case -1:
643  $ipMatchesDevelopmentSystem = GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
644  $exceptionHandlerClassName = $ipMatchesDevelopmentSystem ? $debugExceptionHandlerClassName : $productionExceptionHandlerClassName;
645  $displayErrors = $ipMatchesDevelopmentSystem ? 1 : 0;
646  $exceptionalErrors = $ipMatchesDevelopmentSystem ? $exceptionalErrors : 0;
647  break;
648  case 0:
649  $exceptionHandlerClassName = $productionExceptionHandlerClassName;
650  $displayErrors = 0;
651  break;
652  case 1:
653  $exceptionHandlerClassName = $debugExceptionHandlerClassName;
654  $displayErrors = 1;
655  break;
656  default:
657  // Throw exception if an invalid option is set.
658  throw new \RuntimeException(
659  'The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".',
660  1476046290
661  );
662  }
663  @ini_set('display_errors', $displayErrors);
664 
665  if (!empty($errorHandlerClassName)) {
666  // Register an error handler for the given errorHandlerError
667  $errorHandler = GeneralUtility::makeInstance($errorHandlerClassName, $errorHandlerErrors);
668  $errorHandler->setExceptionalErrors($exceptionalErrors);
669  if (is_callable([$errorHandler, 'setDebugMode'])) {
670  $errorHandler->setDebugMode($displayErrors === 1);
671  }
672  }
673  if (!empty($exceptionHandlerClassName)) {
674  // Registering the exception handler is done in the constructor
675  GeneralUtility::makeInstance($exceptionHandlerClassName);
676  }
677  return $this;
678  }
679 
686  protected function setMemoryLimit()
687  {
688  if ((int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit'] > 16) {
689  @ini_set('memory_limit', ((int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit'] . 'm'));
690  }
691  return $this;
692  }
693 
700  protected function defineTypo3RequestTypes()
701  {
702  define('TYPO3_REQUESTTYPE_FE', 1);
703  define('TYPO3_REQUESTTYPE_BE', 2);
704  define('TYPO3_REQUESTTYPE_CLI', 4);
705  define('TYPO3_REQUESTTYPE_AJAX', 8);
706  define('TYPO3_REQUESTTYPE_INSTALL', 16);
707  }
708 
715  public function setRequestType($requestType)
716  {
717  if (defined('TYPO3_REQUESTTYPE')) {
718  throw new \RuntimeException('TYPO3_REQUESTTYPE has already been set, cannot be called multiple times', 1450561878);
719  }
720  define('TYPO3_REQUESTTYPE', $requestType);
721  return $this;
722  }
723 
732  {
733  $this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
734  return $this;
735  }
736 
744  {
745  define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
746  define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
747  define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
748  return $this;
749  }
750 
759  {
760  unset($GLOBALS['PAGES_TYPES']);
761  unset($GLOBALS['TCA']);
762  unset($GLOBALS['TBE_MODULES']);
763  unset($GLOBALS['TBE_STYLES']);
764  unset($GLOBALS['BE_USER']);
765  // Those set otherwise:
766  unset($GLOBALS['TBE_MODULES_EXT']);
767  unset($GLOBALS['TCA_DESCR']);
768  unset($GLOBALS['LOCAL_LANG']);
769  return $this;
770  }
771 
778  public function initializeTypo3DbGlobal()
779  {
781  $databaseConnection = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
782  $databaseConnection->setDatabaseName(
783  $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'] ?? ''
784  );
785  $databaseConnection->setDatabaseUsername(
786  $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user'] ?? ''
787  );
788  $databaseConnection->setDatabasePassword(
789  $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password'] ?? ''
790  );
791 
792  $databaseHost = $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host'] ?? '';
793  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port'])) {
794  $databaseConnection->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port']);
795  } elseif (strpos($databaseHost, ':') > 0) {
796  // @TODO: Find a way to handle this case in the install tool and drop this
797  list($databaseHost, $databasePort) = explode(':', $databaseHost);
798  $databaseConnection->setDatabasePort($databasePort);
799  }
800  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['unix_socket'])) {
801  $databaseConnection->setDatabaseSocket(
802  $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['unix_socket']
803  );
804  }
805  $databaseConnection->setDatabaseHost($databaseHost);
806 
807  $databaseConnection->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
808 
809  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['persistentConnection'])
810  && $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['persistentConnection']
811  ) {
812  $databaseConnection->setPersistentDatabaseConnection(true);
813  }
814 
815  $isDatabaseHostLocalHost = in_array($databaseHost, ['localhost', '127.0.0.1', '::1'], true);
816  if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driverOptions'])
817  && $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driverOptions'] & MYSQLI_CLIENT_COMPRESS
818  && !$isDatabaseHostLocalHost
819  ) {
820  $databaseConnection->setConnectionCompression(true);
821  }
822 
823  if (!empty($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['initCommands'])) {
824  $commandsAfterConnect = GeneralUtility::trimExplode(
825  LF,
826  str_replace(
827  '\' . LF . \'',
828  LF,
829  $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['initCommands']
830  ),
831  true
832  );
833  $databaseConnection->setInitializeCommandsAfterConnect($commandsAfterConnect);
834  }
835 
836  $GLOBALS['TYPO3_DB'] = $databaseConnection;
837  // $GLOBALS['TYPO3_DB'] needs to be defined first in order to work for DBAL
838  $GLOBALS['TYPO3_DB']->initialize();
839 
840  return $this;
841  }
842 
852  public function checkLockedBackendAndRedirectOrDie($forceProceeding = false)
853  {
854  if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
855  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);
856  }
857  if (@is_file(PATH_typo3conf . 'LOCK_BACKEND') && $forceProceeding === false) {
858  $fileContent = file_get_contents(PATH_typo3conf . 'LOCK_BACKEND');
859  if ($fileContent) {
860  header('Location: ' . $fileContent);
861  } else {
862  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);
863  }
864  die;
865  }
866  return $this;
867  }
868 
877  public function checkBackendIpOrDie()
878  {
879  if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
880  if (!GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
881  throw new \RuntimeException('TYPO3 Backend access denied: The IP address of your client does not match the list of allowed IP addresses.', 1389265900);
882  }
883  }
884  return $this;
885  }
886 
896  {
897  if ((bool)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] && !GeneralUtility::getIndpEnv('TYPO3_SSL')) {
898  if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']) {
899  $sslPortSuffix = ':' . (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'];
900  } else {
901  $sslPortSuffix = '';
902  }
903  list(, $url) = explode('://', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
904  list($server, $address) = explode('/', $url, 2);
905  header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
906  die;
907  }
908  return $this;
909  }
910 
923  public function loadExtensionTables($allowCaching = true)
924  {
925  ExtensionManagementUtility::loadBaseTca($allowCaching);
926  ExtensionManagementUtility::loadExtTables($allowCaching);
927  $this->runExtTablesPostProcessingHooks();
928  return $this;
929  }
930 
937  protected function runExtTablesPostProcessingHooks()
938  {
939  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
940  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
942  $hookObject = GeneralUtility::getUserObj($classReference);
943  if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
944  throw new \UnexpectedValueException(
945  '$hookObject "' . $classReference . '" must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface',
946  1320585902
947  );
948  }
949  $hookObject->processData();
950  }
951  }
952  }
953 
961  public function initializeBackendRouter()
962  {
963  // See if the Routes.php from all active packages have been built together already
964  $cacheIdentifier = 'BackendRoutesFromPackages_' . sha1((TYPO3_version . PATH_site . 'BackendRoutesFromPackages'));
965 
967  $codeCache = $this->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
968  $routesFromPackages = [];
969  if ($codeCache->has($cacheIdentifier)) {
970  // substr is necessary, because the php frontend wraps php code around the cache value
971  $routesFromPackages = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
972  } else {
973  // Loop over all packages and check for a Configuration/Backend/Routes.php file
974  $packageManager = $this->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
975  $packages = $packageManager->getActivePackages();
976  foreach ($packages as $package) {
977  $routesFileNameForPackage = $package->getPackagePath() . 'Configuration/Backend/Routes.php';
978  if (file_exists($routesFileNameForPackage)) {
979  $definedRoutesInPackage = require $routesFileNameForPackage;
980  if (is_array($definedRoutesInPackage)) {
981  $routesFromPackages = array_merge($routesFromPackages, $definedRoutesInPackage);
982  }
983  }
984  $routesFileNameForPackage = $package->getPackagePath() . 'Configuration/Backend/AjaxRoutes.php';
985  if (file_exists($routesFileNameForPackage)) {
986  $definedRoutesInPackage = require $routesFileNameForPackage;
987  if (is_array($definedRoutesInPackage)) {
988  foreach ($definedRoutesInPackage as $routeIdentifier => $routeOptions) {
989  // prefix the route with "ajax_" as "namespace"
990  $routeOptions['path'] = '/ajax' . $routeOptions['path'];
991  $routesFromPackages['ajax_' . $routeIdentifier] = $routeOptions;
992  $routesFromPackages['ajax_' . $routeIdentifier]['ajax'] = true;
993  }
994  }
995  }
996  }
997  // Store the data from all packages in the cache
998  $codeCache->set($cacheIdentifier, serialize($routesFromPackages));
999  }
1000 
1001  // Build Route objects from the data
1002  $router = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\Router::class);
1003  foreach ($routesFromPackages as $name => $options) {
1004  $path = $options['path'];
1005  unset($options['path']);
1006  $route = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\Route::class, $path, $options);
1007  $router->addRoute($name, $route);
1008  }
1009  return $this;
1010  }
1011 
1018  public function initializeBackendUser()
1019  {
1021  $backendUser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
1022  // The global must be available very early, because methods below
1023  // might trigger code which relies on it. See: #45625
1024  $GLOBALS['BE_USER'] = $backendUser;
1025  $backendUser->start();
1026  return $this;
1027  }
1028 
1036  public function initializeBackendAuthentication($proceedIfNoUserIsLoggedIn = false)
1037  {
1038  $GLOBALS['BE_USER']->backendCheckLogin($proceedIfNoUserIsLoggedIn);
1039  return $this;
1040  }
1041 
1048  public function initializeLanguageObject()
1049  {
1051  $GLOBALS['LANG'] = GeneralUtility::makeInstance(\TYPO3\CMS\Lang\LanguageService::class);
1052  $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
1053  return $this;
1054  }
1055 
1063  {
1064  ob_clean();
1065  return $this;
1066  }
1067 
1075  {
1076  if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
1077  if (MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
1078  @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
1079  }
1080  ob_start('ob_gzhandler');
1081  }
1082  return $this;
1083  }
1084 
1091  public function sendHttpHeaders()
1092  {
1093  if (!empty($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers']) && is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers'])) {
1094  foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['HTTP']['Response']['Headers'] as $header) {
1095  header($header);
1096  }
1097  }
1098  return $this;
1099  }
1100 
1109  public function shutdown()
1110  {
1111  $this->sendResponse();
1112  return $this;
1113  }
1114 
1122  public function initializeBackendTemplate()
1123  {
1124  $GLOBALS['TBE_TEMPLATE'] = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
1125  return $this;
1126  }
1127 }
static setPackageManager(PackageManager $packageManager)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static registerExtDirectComponent($endpointName, $callbackClass, $moduleName=null, $accessLevel=null)
static presetApplicationContext(ApplicationContext $applicationContext)
checkLockedBackendAndRedirectOrDie($forceProceeding=false)
initializeBackendAuthentication($proceedIfNoUserIsLoggedIn=false)
static setSingletonInstance($className, SingletonInterface $instance)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
loadConfigurationAndInitialize($allowCaching=true, $packageManagerClassName=\TYPO3\CMS\Core\Package\PackageManager::class)