custom/plugins/SwagEnterpriseSearchPlatform/src/IndexingQuery/IndexingQueryExtension.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swag\EnterpriseSearch\IndexingQuery;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\Struct\Struct;
  5. class IndexingQueryExtension extends Struct
  6. {
  7.     private const KEY 'indexingQuery';
  8.     /**
  9.      * @var array<string, IndexingQueryEntity>
  10.      */
  11.     private $indexingQueryEntityMap;
  12.     /**
  13.      * @var bool
  14.      */
  15.     private $cache true;
  16.     private function __construct()
  17.     {
  18.     }
  19.     public static function addIndexingQueryExtension(Context $context): void
  20.     {
  21.         $extension = new self();
  22.         $context->addExtension(self::KEY$extension);
  23.     }
  24.     public static function getIndexingQueryExtension(Context $context): self
  25.     {
  26.         $extension $context->getExtension(self::KEY);
  27.         if (!$extension instanceof IndexingQueryExtension) {
  28.             throw new \Exception('No Extension available');
  29.         }
  30.         return $extension;
  31.     }
  32.     public static function hasIndexingQueryExtension(Context $context): bool
  33.     {
  34.         return $context->hasExtension(self::KEY);
  35.     }
  36.     public function executeWithoutCache(callable $function): void
  37.     {
  38.         $this->cache false;
  39.         $function();
  40.         $this->cache true;
  41.     }
  42.     public function isCached(): bool
  43.     {
  44.         return $this->cache;
  45.     }
  46.     public function hasIndexingQueryEntityForEntity(string $entityName): bool
  47.     {
  48.         return isset($this->indexingQueryEntityMap[$entityName]);
  49.     }
  50.     public function setIndexingQueryForEntity(IndexingQueryEntity $entity): void
  51.     {
  52.         $this->indexingQueryEntityMap[$entity->getEntityName()] = $entity;
  53.     }
  54.     public function getIndexingQueryEntityForEntity(string $entityName): IndexingQueryEntity
  55.     {
  56.         return $this->indexingQueryEntityMap[$entityName];
  57.     }
  58. }