diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e1bc455918ed3..c3dfe63337816 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2,7 +2,7 @@ parameters: ignoreErrors: - message: "#^Namespace Context is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" - count: 4 + count: 6 path: src/Core/Addon/Module/ModuleManagerBuilder.php - @@ -645,21 +645,11 @@ parameters: count: 1 path: src/Core/Form/IdentifiableObject/DataHandler/OrderReturnFormDataHandler.php - - - message: "#^Class Customer is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" - count: 1 - path: src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php - - message: "#^Namespace CartRule is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" count: 2 path: src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php - - - message: "#^Namespace Customer is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" - count: 1 - path: src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php - - message: "#^Class Employee is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" count: 1 @@ -1025,11 +1015,6 @@ parameters: count: 1 path: src/PrestaShopBundle/Command/ModuleCommand.php - - - message: "#^Namespace Context is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" - count: 2 - path: src/PrestaShopBundle/Controller/Admin/CommonController.php - - message: "#^Class ImageManager is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" count: 1 diff --git a/src/Core/Addon/Module/ModuleManagerBuilder.php b/src/Core/Addon/Module/ModuleManagerBuilder.php index aff779aeb86d9..8c248c9d9e874 100644 --- a/src/Core/Addon/Module/ModuleManagerBuilder.php +++ b/src/Core/Addon/Module/ModuleManagerBuilder.php @@ -29,8 +29,7 @@ use Context; use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Language; -use PrestaShop\PrestaShop\Adapter\Configuration; -use PrestaShop\PrestaShop\Adapter\Currency\CurrencyDataProvider; +use PrestaShop\Decimal\Operation\Rounding; use PrestaShop\PrestaShop\Adapter\HookManager; use PrestaShop\PrestaShop\Adapter\LegacyLogger; use PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider; @@ -39,15 +38,12 @@ use PrestaShop\PrestaShop\Adapter\Tools; use PrestaShop\PrestaShop\Core\Context\ApiClientContext; use PrestaShop\PrestaShop\Core\Context\LanguageContext; -use PrestaShop\PrestaShop\Core\Localization\CLDR\DataLayer\LocaleReference; -use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleDataSource; -use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleRepository; -use PrestaShop\PrestaShop\Core\Localization\CLDR\Reader; -use PrestaShop\PrestaShop\Core\Localization\Currency\CurrencyDataSource; -use PrestaShop\PrestaShop\Core\Localization\Currency\DataLayer\CurrencyInstalled; -use PrestaShop\PrestaShop\Core\Localization\Currency\DataLayer\CurrencyReference; -use PrestaShop\PrestaShop\Core\Localization\Currency\Repository; use PrestaShop\PrestaShop\Core\Localization\Locale; +use PrestaShop\PrestaShop\Core\Localization\Number\Formatter as NumberFormatter; +use PrestaShop\PrestaShop\Core\Localization\Specification\Number as NumberSpecification; +use PrestaShop\PrestaShop\Core\Localization\Specification\NumberCollection; +use PrestaShop\PrestaShop\Core\Localization\Specification\NumberSymbolList; +use PrestaShop\PrestaShop\Core\Localization\Specification\Price as PriceSpecification; use PrestaShop\PrestaShop\Core\Module\ModuleManager; use PrestaShop\PrestaShop\Core\Module\ModuleRepository; use PrestaShop\PrestaShop\Core\Module\SourceHandler\SourceHandlerFactory; @@ -226,7 +222,47 @@ private function getLanguageContext(): LanguageContext /** @var Language $language */ $language = Context::getContext()->language; - $localeRepository = $this->getLocaleRepository(); + // If locale is present in context we can use, if not we create a mock one + // the locale is not used by the ModuleRepository anyway only the language ID is relevant for its internal cache key generation + if (Context::getContext()->currentLocale) { + $locale = Context::getContext()->currentLocale; + } else { + $numberSymbolList = new NumberSymbolList(',', ' ', ';', '%', '-', '+', 'E', '^', '‰', '∞', 'NaN'); + $priceSpecsCollection = new NumberCollection(); + $priceSpecsCollection->add( + 'EUR', + new PriceSpecification( + '#,##0.## ¤', + '-#,##0.## ¤', + ['latn' => $numberSymbolList], + 2, + 2, + true, + 3, + 3, + 'symbol', + '€', + 'EUR' + ) + ); + $numberSpecification = new NumberSpecification( + '#,##0.###', + '-#,##0.###', + [$numberSymbolList], + 3, + 2, + true, + 2, + 3 + ); + $locale = new Locale( + $language->locale, + $numberSpecification, + $priceSpecsCollection, + new NumberFormatter(Rounding::ROUND_HALF_UP, 'latn') + ); + } + self::$languageContext = new LanguageContext( $language->id, $language->name, @@ -236,31 +272,12 @@ private function getLanguageContext(): LanguageContext $language->is_rtl, $language->date_format_lite, $language->date_format_full, - $localeRepository->getLocale($language->locale) + $locale ); return self::$languageContext; } - private function getLocaleRepository(): Locale\Repository - { - $localeDataReference = new LocaleReference(new Reader()); - $localeDataSource = new LocaleDataSource($localeDataReference); - $cldrLocaleRepository = new LocaleRepository($localeDataSource); - - $configuration = new Configuration(); - $currencyReference = new CurrencyReference($cldrLocaleRepository); - $currencyDataProvider = new CurrencyDataProvider($configuration, (int) $configuration->get('PS_SHOP_DEFAULT')); - $currencyInstalled = new CurrencyInstalled($currencyDataProvider); - $currencyDataSource = new CurrencyDataSource($currencyReference, $currencyInstalled); - $currencyRepository = new Repository($currencyDataSource); - - return new Locale\Repository( - $cldrLocaleRepository, - $currencyRepository, - ); - } - protected function getConfigDir() { return _PS_ROOT_DIR_ . '/app/config';