vendor/shopware/core/Framework/Rule/Collector/RuleConditionRegistry.php line 22

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Rule\Collector;
  3. use Shopware\Core\Framework\Rule\Exception\InvalidConditionException;
  4. use Shopware\Core\Framework\Rule\Rule;
  5. class RuleConditionRegistry
  6. {
  7.     /**
  8.      * @var array<string, Rule>
  9.      */
  10.     private array $rules;
  11.     /**
  12.      * @internal
  13.      *
  14.      * @param iterable<Rule> $taggedRules
  15.      */
  16.     public function __construct(iterable $taggedRules)
  17.     {
  18.         $this->mapRules($taggedRules);
  19.     }
  20.     /**
  21.      * @return array<string>
  22.      */
  23.     public function getNames(): array
  24.     {
  25.         return array_keys($this->rules);
  26.     }
  27.     public function has(string $name): bool
  28.     {
  29.         try {
  30.             $this->getRuleInstance($name);
  31.         } catch (InvalidConditionException $exception) {
  32.             return false;
  33.         }
  34.         return true;
  35.     }
  36.     public function getRuleInstance(string $name): Rule
  37.     {
  38.         if (!\array_key_exists($name$this->rules)) {
  39.             throw new InvalidConditionException($name);
  40.         }
  41.         return $this->rules[$name];
  42.     }
  43.     /**
  44.      * @return class-string<Rule>
  45.      */
  46.     public function getRuleClass(string $name): string
  47.     {
  48.         return \get_class($this->getRuleInstance($name));
  49.     }
  50.     /**
  51.      * @param iterable<Rule> $taggedRules
  52.      */
  53.     private function mapRules(iterable $taggedRules): void
  54.     {
  55.         $this->rules = [];
  56.         foreach ($taggedRules as $rule) {
  57.             $this->rules[$rule->getName()] = $rule;
  58.         }
  59.     }
  60. }