diff --git a/typo3/sysext/core/Classes/Core/Bootstrap.php b/typo3/sysext/core/Classes/Core/Bootstrap.php index baae88cefde59805a694ad45457d80a989a5244c..36c481f362ee155c8203de990b07ecc3eeebd116 100644 --- a/typo3/sysext/core/Classes/Core/Bootstrap.php +++ b/typo3/sysext/core/Classes/Core/Bootstrap.php @@ -30,7 +30,6 @@ use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend; use TYPO3\CMS\Core\Configuration\ConfigurationManager; use TYPO3\CMS\Core\Imaging\IconRegistry; use TYPO3\CMS\Core\IO\PharStreamWrapperInterceptor; -use TYPO3\CMS\Core\Localization\Locales; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Package\FailsafePackageManager; use TYPO3\CMS\Core\Package\PackageManager; @@ -102,7 +101,6 @@ class Bootstrap static::initializeRuntimeActivatedPackagesFromConfiguration($packageManager); static::setDefaultTimezone(); - $locales = Locales::initialize(); static::setMemoryLimit(); $assetsCache = static::createCache('assets', $disableCaching); @@ -131,7 +129,6 @@ class Bootstrap 'cache.assets' => $assetsCache, CacheManager::class => $cacheManager, PackageManager::class => $packageManager, - Locales::class => $locales, ]; return new class($defaultContainerEntries) implements ContainerInterface { diff --git a/typo3/sysext/core/Classes/Localization/LanguageService.php b/typo3/sysext/core/Classes/Localization/LanguageService.php index ae277e55d6ecafec78af53ecc7cd007fe126b610..e1ea16278bc57e1d7ccdbeefbfdf7bbcbc84f354 100644 --- a/typo3/sysext/core/Classes/Localization/LanguageService.php +++ b/typo3/sysext/core/Classes/Localization/LanguageService.php @@ -90,10 +90,9 @@ class LanguageService public function init($languageKey) { // Find the requested language in this list based on the $languageKey - /** @var \TYPO3\CMS\Core\Localization\Locales $locales */ $locales = GeneralUtility::makeInstance(Locales::class); // Language is found. Configure it: - if (in_array($languageKey, $locales->getLocales())) { + if (in_array($languageKey, $locales->getLocales(), true)) { // The current language key $this->lang = $languageKey; $this->languageDependencies[] = $languageKey; diff --git a/typo3/sysext/core/Classes/Localization/Locales.php b/typo3/sysext/core/Classes/Localization/Locales.php index 0dcd7d6a5249fe56d759b36ddd91420ee2726aea..abdefcbaa6face7e35202c2d537d68bbe2f3945a 100644 --- a/typo3/sysext/core/Classes/Localization/Locales.php +++ b/typo3/sysext/core/Classes/Localization/Locales.php @@ -126,31 +126,36 @@ class Locales implements SingletonInterface 'fr_CA' => ['fr'] ]; - /** - * Initializes the languages. - * @return Locales - */ - public static function initialize(): Locales + public function __construct() { - $instance = GeneralUtility::makeInstance(self::class); // Allow user-defined locales foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'] ?? [] as $locale => $name) { - if (!isset($instance->languages[$locale])) { - $instance->languages[$locale] = $name; + if (!isset($this->languages[$locale])) { + $this->languages[$locale] = $name; } // Initializes the locale dependencies with TYPO3 supported locales if (strlen($locale) === 5) { - $instance->localeDependencies[$locale] = [substr($locale, 0, 2)]; + $this->localeDependencies[$locale] = [substr($locale, 0, 2)]; } } // Merge user-provided locale dependencies if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'] ?? null)) { - $instance->localeDependencies = array_replace_recursive( - $instance->localeDependencies, + $this->localeDependencies = array_replace_recursive( + $this->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'] ); } - return $instance; + } + + /** + * Initializes the languages. + * @return Locales + * @deprecated will be removed in TYPO3 v11.0. Use the regular constructor instead. + */ + public static function initialize(): Locales + { + trigger_error('Locales::initialize() will be removed in TYPO3 v11.0, fetch the instance of a class via GeneralUtility::makeInstance() or DependencyInjection', E_USER_DEPRECATED); + return new self; } /** diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-88569-LocalesinitializeInFavorOfRegularSingletonInstance.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-88569-LocalesinitializeInFavorOfRegularSingletonInstance.rst new file mode 100644 index 0000000000000000000000000000000000000000..998890a27ad7bf889ed344999f9470998765f03b --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-88569-LocalesinitializeInFavorOfRegularSingletonInstance.rst @@ -0,0 +1,39 @@ +.. include:: ../../Includes.txt + +================================================================================== +Deprecation: #88569 - Locales::initialize() in favor of regular singleton instance +================================================================================== + +See :issue:`88569` + +Description +=========== + +The method :php:`Locales::initialize()` has been deprecated. It was a workaround to re-initialize +the Singleton Instance of the PHP class `Locales` for user-defined locales, which were +loaded by an extensions' `ext_localconf.php`. + +Locales is now initialized only when needed, and not during the early bootstrap process, +making this functionality obsolete, as this is taken care of within the regular constructor. + + +Impact +====== + +Calling :php:`Locales::initialize()` will trigger a deprecation notice. + + +Affected Installations +====================== + +Any TYPO3 installation with a third-party extension calling `Locales::initialize()` directly. + + +Migration +========= + +Replace the function call by a regular :php:`GeneralUtility::makeInstance(Locales::class);` call +or use Dependency Injection (Constructor Injection or ObjectManager) to fetch an instance of +the Locales class. + +.. index:: PHP-API, FullyScanned \ No newline at end of file diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index c136f1d453cfd6d5c675b3e1d6fe35c17f5ecfde..7e9b9c01bf6fbf2dee42b8545e8304dd9e0fde8f 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -1929,8 +1929,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface GeneralUtility::callUserFunction($_funcRef, $_params, $this); } - Locales::initialize(); - $siteLanguage = $this->getCurrentSiteLanguage(); if (!$siteLanguage) { throw new PageNotFoundException('Frontend cannot be displayed, as there is no language available', 1557924417); diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php index 3e7895f40adc5d51a1f5ad608161fffa7443bed4..bbd9dd8ed82eff5f46a1d050a4da5cdfac98db7b 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php @@ -910,4 +910,11 @@ return [ 'Breaking-87957-DoNotMagicallyRegisterValidators.rst', ], ], + 'TYPO3\CMS\Core\Localization\Locales::initialize' => [ + 'numberOfMandatoryArguments' => 0, + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-88569-LocalesinitializeInFavorOfRegularSingletonInstance.rst', + ], + ], ];