Skip to content

Commit

Permalink
Simply locale creation, that is not used anyway, to fix the performan…
Browse files Browse the repository at this point in the history
…ce drop from the initial refacto
  • Loading branch information
jolelievre committed Nov 14, 2024
1 parent dd932a6 commit 3a28a02
Showing 1 changed file with 48 additions and 31 deletions.
79 changes: 48 additions & 31 deletions src/Core/Addon/Module/ModuleManagerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
use Context;

Check failure on line 29 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Ignored error pattern #^Namespace Context is forbidden, No legacy calls inside the prestashop bundle\. Please create an interface and an adapter if you need to\.$# in path /home/runner/work/PrestaShop/PrestaShop/src/Core/Addon/Module/ModuleManagerBuilder.php is expected to occur 4 times, but occurred 6 times.

Check failure on line 29 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Ignored error pattern #^Namespace Context is forbidden, No legacy calls inside the prestashop bundle\. Please create an interface and an adapter if you need to\.$# in path /home/runner/work/PrestaShop/PrestaShop/src/Core/Addon/Module/ModuleManagerBuilder.php is expected to occur 4 times, but occurred 6 times.

Check failure on line 29 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Ignored error pattern #^Namespace Context is forbidden, No legacy calls inside the prestashop bundle\. Please create an interface and an adapter if you need to\.$# in path /home/runner/work/PrestaShop/PrestaShop/src/Core/Addon/Module/ModuleManagerBuilder.php is expected to occur 4 times, but occurred 6 times.
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {

Check failure on line 227 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Namespace Context is forbidden, No legacy calls inside the prestashop bundle. Please create an interface and an adapter if you need to.

Check failure on line 227 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Namespace Context is forbidden, No legacy calls inside the prestashop bundle. Please create an interface and an adapter if you need to.

Check failure on line 227 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Namespace Context is forbidden, No legacy calls inside the prestashop bundle. Please create an interface and an adapter if you need to.
$locale = Context::getContext()->currentLocale;

Check failure on line 228 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Namespace Context is forbidden, No legacy calls inside the prestashop bundle. Please create an interface and an adapter if you need to.

Check failure on line 228 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Namespace Context is forbidden, No legacy calls inside the prestashop bundle. Please create an interface and an adapter if you need to.

Check failure on line 228 in src/Core/Addon/Module/ModuleManagerBuilder.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Namespace Context is forbidden, No legacy calls inside the prestashop bundle. Please create an interface and an adapter if you need to.
} 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,
Expand All @@ -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';
Expand Down

0 comments on commit 3a28a02

Please sign in to comment.