vendor/ibexa/product-catalog/src/lib/Local/Repository/VatCategory/VatCategoryProvider.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\ProductCatalog\Local\Repository\VatCategory;
  8. use Ibexa\Contracts\ProductCatalog\Values\VatCategoryInterface;
  9. use Ibexa\Core\MVC\Symfony\Event\ScopeChangeEvent;
  10. use Ibexa\Core\MVC\Symfony\MVCEvents;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. final class VatCategoryProvider implements EventSubscriberInterfaceVatCategoryProviderInterface
  13. {
  14.     private VatCategoryPoolFactoryInterface $factory;
  15.     private ?VatCategoryPoolInterface $pool null;
  16.     public function __construct(VatCategoryPoolFactoryInterface $categoryPoolFactory)
  17.     {
  18.         $this->factory $categoryPoolFactory;
  19.     }
  20.     public function getVatCategory(string $regionstring $identifier): VatCategoryInterface
  21.     {
  22.         return $this->getPool()->getVatCategory($region$identifier);
  23.     }
  24.     public function getVatCategories(string $region): array
  25.     {
  26.         return $this->getPool()->getVatCategories($region);
  27.     }
  28.     private function getPool(): VatCategoryPoolInterface
  29.     {
  30.         if ($this->pool === null) {
  31.             $this->pool $this->factory->createPool();
  32.         }
  33.         return $this->pool;
  34.     }
  35.     public function onScopeChange(ScopeChangeEvent $event): void
  36.     {
  37.         $this->pool null;
  38.     }
  39.     public static function getSubscribedEvents(): array
  40.     {
  41.         return [
  42.             MVCEvents::CONFIG_SCOPE_CHANGE => 'onScopeChange',
  43.         ];
  44.     }
  45. }