src/SettingsProvider/EcommerceSettingsList.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\SettingsProvider;
  3. use App\Entity\EcommerceGeneralSettings;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  6. use Symfony\Contracts\Cache\ItemInterface;
  7. class EcommerceSettingsList
  8. {
  9.     public function __construct(private ManagerRegistry $managerRegistry)
  10.     {
  11.         $this->cache = new FilesystemAdapter;
  12.     }
  13.     public function getCurrency(): string
  14.     {
  15.         $item $this->cache->get('settings.currency', function (ItemInterface $item) {
  16.             return $this->settingsDatabase()->getCurrencyType() ?: '';
  17.         });
  18.         return $item ?: '';
  19.     }
  20.     public function getCurrencyOnRight(): bool
  21.     {
  22.         return $this->cache->get('settings.currencyOnRight', function (ItemInterface $item) {
  23.             return $this->settingsDatabase()->isCurrencySignOnRight() ?: true;
  24.         });
  25.     }
  26.     public function getShowCurrencySign(): bool
  27.     {
  28.         return  $this->cache->get('settings.currencySign', function (ItemInterface $item) {
  29.             return $this->settingsDatabase()->isShowCurrencySign() ?: true;
  30.         });
  31.     }
  32.     public function getCurrencySignType(): string
  33.     {
  34.         $item $this->cache->get('settings.currencySignType', function (ItemInterface $item) {
  35.             return $this->settingsDatabase()->getCurrencySignType() ?: '';
  36.         });
  37.         return $item ?: '';
  38.     }
  39.     public function getProductImagePlaceholder(): string
  40.     {
  41.         $item $this->cache->get('settings.productImagePlaceholder', function (ItemInterface $item) {
  42.             return $this->settingsDatabase()->getProductImagePlaceholder() ?: '';
  43.         });
  44.         return $item ?: '';
  45.     }
  46.     public function getWeightUnitType(): string
  47.     {
  48.         $item $this->cache->get('settings.weightUnitType', function (ItemInterface $item) {
  49.             return $this->settingsDatabase()->getWeightUnitType() ?: '';
  50.         });
  51.         return $item ?: '';
  52.     }
  53.     public function getLengthUnitType(): string
  54.     {
  55.         $item $this->cache->get('settings.lengthUnitType', function (ItemInterface $item) {
  56.             return $this->settingsDatabase()->getLengthUnitType() ?: '';
  57.         });
  58.         return $item ?: '';
  59.     }
  60.     private function settingsDatabase(): EcommerceGeneralSettings
  61.     {
  62.         return $this->managerRegistry->getRepository(EcommerceGeneralSettings::class)->findOneBy([]);
  63.     }
  64. }