2 namespace TYPO3\CMS\Core\Core;
89 $this->requestId = substr(md5(uniqid(
'',
true)), 0, 13);
98 return self::$usesComposerClassLoading;
116 if (is_null(static::$instance)) {
117 $applicationContext = getenv(
'TYPO3_CONTEXT') ?: (getenv(
'REDIRECT_TYPO3_CONTEXT') ?:
'Production');
120 return static::$instance;
170 ->loadConfigurationAndInitialize()
171 ->loadTypo3LoadedExtAndExtLocalconf(
true)
172 ->setFinalCachingFrameworkCacheConfiguration()
173 ->defineLoggingAndExceptionConstants()
174 ->unsetReservedGlobalVariables()
175 ->initializeTypo3DbGlobal();
209 $this->
setEarlyInstance(\Composer\Autoload\ClassLoader::class, $classLoader);
210 if (defined(
'TYPO3_COMPOSER_MODE') && TYPO3_COMPOSER_MODE) {
211 self::$usesComposerClassLoading =
true;
225 $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
226 $this->
setEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class, $configurationManager);
227 return file_exists($configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf .
'PackageStates.php');
237 $backPathToSiteRoot = str_repeat(
'../', count(explode(
'/', $relativePathPart)) - 1);
238 header(
'Location: ' . $backPathToSiteRoot .
'typo3/sysext/install/Start/Install.php');
251 $this->availableRequestHandlers[] = $requestHandler;
265 protected function resolveRequestHandler($request)
267 $suitableRequestHandlers = array();
268 foreach ($this->availableRequestHandlers as $requestHandlerClassName) {
271 if ($requestHandler->canHandleRequest($request)) {
272 $priority = $requestHandler->getPriority();
273 if (isset($suitableRequestHandlers[$priority])) {
274 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);
276 $suitableRequestHandlers[$priority] = $requestHandler;
279 if (empty($suitableRequestHandlers)) {
280 throw new \TYPO3\CMS\Core\Exception(
'No suitable request handler found.', 1225418233);
282 ksort($suitableRequestHandlers);
283 return array_pop($suitableRequestHandlers);
299 $requestHandler = $this->resolveRequestHandler($request);
302 $this->response = $requestHandler->handleRequest($request);
313 if ($this->response instanceof \Psr\Http\Message\ResponseInterface) {
314 if (!headers_sent()) {
315 foreach ($this->response->getHeaders() as $name => $values) {
316 header($name .
': ' . implode(
', ', $values));
322 if (http_response_code() === 200) {
323 header(
'HTTP/' . $this->response->getProtocolVersion() .
' ' . $this->response->getStatusCode() .
' ' . $this->response->getReasonPhrase());
326 echo $this->response->getBody()->__toString();
343 $this->earlyInstances[$objectName] =
$instance;
356 if (!isset($this->earlyInstances[$objectName])) {
357 throw new \TYPO3\CMS\Core\Exception(
'Unknown early instance "' . $objectName .
'"', 1365167380);
359 return $this->earlyInstances[$objectName];
385 ->initializeErrorHandling();
386 if (!$allowCaching) {
390 ->initializePackageManagement($packageManagerClassName)
391 ->initializeRuntimeActivatedPackagesFromConfiguration()
392 ->defineDatabaseConstants()
393 ->defineUserAgentConstant()
394 ->registerExtDirectComponents()
395 ->setCacheHashOptions()
396 ->setDefaultTimezone()
397 ->initializeL10nLocales()
398 ->convertPageNotFoundHandlingToBoolean()
400 ->defineTypo3RequestTypes();
415 public function initializePackageManagement($packageManagerClassName)
418 $packageManager =
new $packageManagerClassName();
419 $this->
setEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
421 $packageManager->injectCoreCache($this->
getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache(
'cache_core'));
423 $dependencyResolver->injectDependencyOrderingService(
GeneralUtility::makeInstance(\TYPO3\CMS\Core\Service\DependencyOrderingService::class));
424 $packageManager->injectDependencyResolver($dependencyResolver);
425 $packageManager->initialize($this);
439 ClassLoadingInformation::dumpClassLoadingInformation();
451 protected function initializeRuntimeActivatedPackagesFromConfiguration()
453 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'runtimeActivatedPackages']) && is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'runtimeActivatedPackages'])) {
455 $packageManager = $this->
getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
456 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'runtimeActivatedPackages'] as $runtimeAddedPackageKey) {
457 $packageManager->activatePackageDuringRuntime($runtimeAddedPackageKey);
472 ExtensionManagementUtility::loadExtLocalconf($allowCaching);
486 $configurationManager = $this->
getEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
487 }
catch (\TYPO3\CMS\Core\
Exception $exception) {
488 $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
489 $this->
setEarlyInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class, $configurationManager);
491 $configurationManager->exportConfiguration();
503 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'caching'][
'cacheConfigurations'][
'cache_core'][
'backend']
504 = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class;
505 unset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'caching'][
'cacheConfigurations'][
'cache_core'][
'options']);
516 define(
'TYPO3_db',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'database']);
517 define(
'TYPO3_db_username',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'username']);
518 define(
'TYPO3_db_password',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'password']);
519 define(
'TYPO3_db_host',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host']);
521 define(
'TYPO3_extTableDef_script',
522 isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'extTablesDefinitionScript'])
523 ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'extTablesDefinitionScript']
535 define(
'TYPO3_user_agent',
'User-Agent: ' .
$GLOBALS[
'TYPO3_CONF_VARS'][
'HTTP'][
'userAgent']);
546 if (TYPO3_MODE ===
'BE') {
548 'TYPO3.Components.PageTree.DataProvider',
549 \TYPO3\CMS\Backend\Tree\Pagetree\ExtdirectTreeDataProvider::class
552 'TYPO3.Components.PageTree.Commands',
553 \TYPO3\CMS\Backend\Tree\Pagetree\ExtdirectTreeCommands::class
556 'TYPO3.Components.PageTree.ContextMenuDataProvider',
557 \TYPO3\CMS\Backend\ContextMenu\Pagetree\Extdirect\ContextMenuConfiguration::class
560 'TYPO3.ExtDirectStateProvider.ExtDirect',
561 \TYPO3\CMS\Backend\InterfaceState\ExtDirect\DataProvider::class
564 'TYPO3.Components.DragAndDrop.CommandController',
565 ExtensionManagementUtility::extPath(
'backend') .
'Classes/View/PageLayout/Extdirect/ExtdirectPageCommands.php:' . \TYPO3\CMS\Backend\View\PageLayout\ExtDirect\ExtdirectPageCommands::class
580 $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
581 $cacheManager->setCacheConfigurations(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'caching'][
'cacheConfigurations']);
584 $cacheFactory = new \TYPO3\CMS\Core\Cache\CacheFactory(
'production', $cacheManager);
587 $this->
setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
598 $GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'cacheHash'] = array(
603 if (trim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'cHashExcludedParametersIfEmpty']) ===
'*') {
604 $GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'cacheHash'][
'excludeAllEmptyParameters'] =
true;
618 $timeZone =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'phpTimeZone'];
619 if (empty($timeZone)) {
621 $defaultTimeZone = @date_default_timezone_get();
622 if ($defaultTimeZone !==
'') {
623 $timeZone = $defaultTimeZone;
629 date_default_timezone_set($timeZone);
640 \TYPO3\CMS\Core\Localization\Locales::initialize();
653 if (!strcasecmp(
$GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'pageNotFound_handling'],
'TRUE')) {
654 $GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'pageNotFound_handling'] =
true;
667 $productionExceptionHandlerClassName =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'productionExceptionHandler'];
668 $debugExceptionHandlerClassName =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'debugExceptionHandler'];
670 $errorHandlerClassName =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'errorHandler'];
671 $errorHandlerErrors =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'errorHandlerErrors'];
672 $exceptionalErrors =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'exceptionalErrors'];
674 $displayErrorsSetting = (int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'displayErrors'];
675 switch ($displayErrorsSetting) {
677 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"');
681 $exceptionHandlerClassName = $ipMatchesDevelopmentSystem ? $debugExceptionHandlerClassName : $productionExceptionHandlerClassName;
682 $displayErrors = $ipMatchesDevelopmentSystem ? 1 : 0;
683 $exceptionalErrors = $ipMatchesDevelopmentSystem ? $exceptionalErrors : 0;
686 $exceptionHandlerClassName = $productionExceptionHandlerClassName;
690 $exceptionHandlerClassName = $debugExceptionHandlerClassName;
695 throw new \RuntimeException(
'The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".');
697 @ini_set(
'display_errors', $displayErrors);
699 if (!empty($errorHandlerClassName)) {
702 $errorHandler->setExceptionalErrors($exceptionalErrors);
703 if (is_callable(array($errorHandler,
'setDebugMode'))) {
704 $errorHandler->setDebugMode($displayErrors === 1);
707 if (!empty($exceptionHandlerClassName)) {
722 if ((
int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'setMemoryLimit'] > 16) {
723 @ini_set(
'memory_limit', ((
int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'setMemoryLimit'] .
'm'));
736 define(
'TYPO3_REQUESTTYPE_FE', 1);
737 define(
'TYPO3_REQUESTTYPE_BE', 2);
738 define(
'TYPO3_REQUESTTYPE_CLI', 4);
739 define(
'TYPO3_REQUESTTYPE_AJAX', 8);
740 define(
'TYPO3_REQUESTTYPE_INSTALL', 16);
741 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));
754 $this->
getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->setCacheConfigurations(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'caching'][
'cacheConfigurations']);
766 define(
'TYPO3_DLOG',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enable_DLOG']);
767 define(
'TYPO3_ERROR_DLOG',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enable_errorDLOG']);
768 define(
'TYPO3_EXCEPTION_DLOG',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enable_exceptionDLOG']);
800 public function initializeTypo3DbGlobal()
804 $databaseConnection->setDatabaseName(TYPO3_db);
805 $databaseConnection->setDatabaseUsername(TYPO3_db_username);
806 $databaseConnection->setDatabasePassword(TYPO3_db_password);
808 $databaseHost = TYPO3_db_host;
809 if (isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port'])) {
810 $databaseConnection->setDatabasePort(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port']);
811 }
elseif (strpos($databaseHost,
':') > 0) {
813 list($databaseHost, $databasePort) = explode(
':', $databaseHost);
814 $databaseConnection->setDatabasePort($databasePort);
816 if (isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket'])) {
817 $databaseConnection->setDatabaseSocket(
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket']);
819 $databaseConnection->setDatabaseHost($databaseHost);
821 $databaseConnection->debugOutput =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'sqlDebug'];
824 isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'no_pconnect'])
825 && !
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'no_pconnect']
827 $databaseConnection->setPersistentDatabaseConnection(
true);
830 $isDatabaseHostLocalHost = $databaseHost ===
'localhost' || $databaseHost ===
'127.0.0.1' || $databaseHost ===
'::1';
832 isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'dbClientCompress'])
833 &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'dbClientCompress']
834 && !$isDatabaseHostLocalHost
836 $databaseConnection->setConnectionCompression(
true);
839 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'setDBinit'])) {
842 str_replace(
'\' . LF . \
'', LF,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'setDBinit']),
845 $databaseConnection->setInitializeCommandsAfterConnect($commandsAfterConnect);
848 $GLOBALS[
'TYPO3_DB'] = $databaseConnection;
866 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'adminOnly'] < 0) {
867 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);
869 if (@is_file(PATH_typo3conf .
'LOCK_BACKEND') && $forceProceeding ===
false) {
872 header(
'Location: ' . $fileContent);
874 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);
891 if (trim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'IPmaskList'])) {
893 throw new \RuntimeException(
'TYPO3 Backend access denied: The IP address of your client does not match the list of allowed IP addresses.', 1389265900);
909 if ((
int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'lockSSL']) {
911 if ((
int)$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'lockSSL'] === 2) {
912 if ((
int)$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'lockSSLPort']) {
913 $sslPortSuffix =
':' . (int)$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'lockSSLPort'];
919 header(
'Location: https://' .
$server . $sslPortSuffix .
'/' . $address);
922 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);
942 public function loadCachedTca()
944 $cacheIdentifier =
'tca_fe_' . sha1((TYPO3_version . PATH_site .
'tca_fe'));
946 $codeCache = $this->
getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache(
'cache_core');
947 if ($codeCache->has($cacheIdentifier)) {
949 $GLOBALS[
'TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
952 $codeCache->set($cacheIdentifier, serialize(
$GLOBALS[
'TCA']));
971 ExtensionManagementUtility::loadBaseTca($allowCaching);
972 ExtensionManagementUtility::loadExtTables($allowCaching);
974 $this->runExtTablesPostProcessingHooks();
994 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
995 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
996 global $PAGES_TYPES, $TBE_STYLES;
999 $extTablesFile = PATH_typo3conf . TYPO3_extTableDef_script;
1000 if (file_exists($extTablesFile) && is_file($extTablesFile)) {
1002 'Using typo3conf/' . TYPO3_extTableDef_script .
' is deprecated and will be removed with TYPO3 CMS 8. Please move your TCA overrides'
1003 .
' to Configuration/TCA/Overrides of your project specific extension, or slot the signal "tcaIsBeingBuilt" for further processing.'
1005 include $extTablesFile;
1015 protected function runExtTablesPostProcessingHooks()
1017 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'GLOBAL'][
'extTablesInclusion-PostProcessing'])) {
1018 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'GLOBAL'][
'extTablesInclusion-PostProcessing'] as $classReference) {
1021 if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
1022 throw new \UnexpectedValueException(
1023 '$hookObject "' . $classReference .
'" must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface',
1027 $hookObject->processData();
1044 \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
1055 public function initializeBackendRouter()
1057 $packageManager = $this->
getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
1060 $cacheIdentifier =
'BackendRoutesFromPackages_' . sha1((TYPO3_version . PATH_site .
'BackendRoutesFromPackages'));
1063 $codeCache = $this->
getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache(
'cache_core');
1064 $routesFromPackages = array();
1065 if ($codeCache->has($cacheIdentifier)) {
1067 $routesFromPackages = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
1070 $packages = $packageManager->getActivePackages();
1071 foreach ($packages as $package) {
1072 $routesFileNameForPackage = $package->getPackagePath() .
'Configuration/Backend/Routes.php';
1073 if (file_exists($routesFileNameForPackage)) {
1074 $definedRoutesInPackage = require $routesFileNameForPackage;
1075 if (is_array($definedRoutesInPackage)) {
1076 $routesFromPackages += $definedRoutesInPackage;
1079 $routesFileNameForPackage = $package->getPackagePath() .
'Configuration/Backend/AjaxRoutes.php';
1080 if (file_exists($routesFileNameForPackage)) {
1081 $definedRoutesInPackage = require $routesFileNameForPackage;
1082 if (is_array($definedRoutesInPackage)) {
1083 foreach ($definedRoutesInPackage as $routeIdentifier => $routeOptions) {
1085 $routeOptions[
'path'] =
'/ajax' . $routeOptions[
'path'];
1086 $routesFromPackages[
'ajax_' . $routeIdentifier] = $routeOptions;
1087 $routesFromPackages[
'ajax_' . $routeIdentifier][
'ajax'] =
true;
1093 $codeCache->set($cacheIdentifier, serialize($routesFromPackages));
1098 foreach ($routesFromPackages as $name => $options) {
1099 $path = $options[
'path'];
1100 unset($options[
'path']);
1102 $router->addRoute($name, $route);
1113 public function initializeBackendUser()
1117 $backendUser->warningEmail =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'warning_email_addr'];
1118 $backendUser->lockIP =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'lockIP'];
1119 $backendUser->auth_timeout_field = (int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'sessionTimeout'];
1120 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
1121 $backendUser->dontSetCookie =
true;
1125 $GLOBALS[
'BE_USER'] = $backendUser;
1126 $backendUser->start();
1139 $GLOBALS[
'BE_USER']->backendCheckLogin($proceedIfNoUserIsLoggedIn);
1149 public function initializeLanguageObject()
1177 if (extension_loaded(
'zlib') &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'compressionLevel']) {
1179 @ini_set(
'zlib.output_compression_level',
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'compressionLevel']);
1181 ob_start(
'ob_gzhandler');
1194 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'HTTP'][
'Response'][
'Headers']) && is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'HTTP'][
'Response'][
'Headers'])) {
1195 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'HTTP'][
'Response'][
'Headers'] as $header) {