* @implements \IteratorAggregate * @internal * @final */ class RuleSet implements \IteratorAggregate, \Countable { public const TYPE_PACKAGE = 0; public const TYPE_REQUEST = 1; public const TYPE_LEARNED = 4; const TYPES = [ self::TYPE_PACKAGE => 'PACKAGE', self::TYPE_REQUEST => 'REQUEST', self::TYPE_LEARNED => 'LEARNED', ]; /** * READ-ONLY: Lookup table for rule id to rule object * * @var array */ public $ruleById = []; /** @var array */ protected $rules; /** @var 0|positive-int */ protected $nextRuleId = 0; /** @var array */ protected $rulesByHash = []; public function __construct() { foreach ($this->getTypes() as $type) { $this->rules[$type] = []; } } /** * @param self::TYPE_* $type */ public function add(Rule $rule, $type): void { if (!isset(self::TYPES[$type])) { throw new \OutOfBoundsException('Unknown rule type: ' . $type); } $hash = $rule->getHash(); // Do not add if rule already exists if (isset($this->rulesByHash[$hash])) { $potentialDuplicates = $this->rulesByHash[$hash]; if (\is_array($potentialDuplicates)) { foreach ($potentialDuplicates as $potentialDuplicate) { if ($rule->equals($potentialDuplicate)) { return; } } } else { if ($rule->equals($potentialDuplicates)) { return; } } } if (!isset($this->rules[$type])) { $this->rules[$type] = []; } $this->rules[$type][] = $rule; $this->ruleById[$this->nextRuleId] = $rule; $rule->setType($type); $this->nextRuleId++; if (!isset($this->rulesByHash[$hash])) { $this->rulesByHash[$hash] = $rule; } elseif (\is_array($this->rulesByHash[$hash])) { $this->rulesByHash[$hash][] = $rule; } else { $originalRule = $this->rulesByHash[$hash]; $this->rulesByHash[$hash] = [$originalRule, $rule]; } } public function count(): int { return $this->nextRuleId; } public function ruleById(int $id): Rule { return $this->ruleById[$id]; } /** * @return array */ public function getRules(): array { return $this->rules; } public function getIterator(): RuleSetIterator { return new RuleSetIterator($this->getRules()); } /** * @param self::TYPE_*|array $types */ public function getIteratorFor($types): RuleSetIterator { if (!\is_array($types)) { $types = [$types]; } $allRules = $this->getRules(); /** @var array $rules */ $rules = []; foreach ($types as $type) { $rules[$type] = $allRules[$type]; } return new RuleSetIterator($rules); } /** * @param array|self::TYPE_* $types */ public function getIteratorWithout($types): RuleSetIterator { if (!\is_array($types)) { $types = [$types]; } $rules = $this->getRules(); foreach ($types as $type) { unset($rules[$type]); } return new RuleSetIterator($rules); } /** * @return array{self::TYPE_PACKAGE, self::TYPE_REQUEST, self::TYPE_LEARNED} */ public function getTypes(): array { $types = self::TYPES; return array_keys($types); } public function getPrettyString( ?RepositorySet $repositorySet = null, ?Request $request = null, ?Pool $pool = null, bool $isVerbose = false, ): string { $string = "\n"; foreach ($this->rules as $type => $rules) { $string .= str_pad(self::TYPES[$type], 8, ' ') . ": "; foreach ($rules as $rule) { $string .= ($repositorySet && $request && $pool ? $rule->getPrettyString($repositorySet, $request, $pool, $isVerbose) : $rule)."\n"; } $string .= "\n\n"; } return $string; } public function __toString(): string { return $this->getPrettyString(); } } __halt_compiler();----SIGNATURE:----HEi3gDwHTW28mPSf2lJZPd6mH30J3NtWR8ud3nirKhwGLHnG4kRJzyHMfeSLV0bEdi5ZDcOVPij1DfexZWaR5fZm9pPEH/4JtBimduW17WD3rk2Np+BaxaHiJh+UevpLvsAQeOYKwIzpeXnhC/iCdqGVfVywFqPqWp0yYm56IXOanOSatzyH4uaePHUakSw701xumNI6tymc9bbOGyykoOcjB3qJHVBw93s3zjBsikH/Yt3naYjUBarlJ6Tb+fMHo/wix1ln2geUyvy1VnCCe6JGr8epSggv7/wdItevm7As1rcqNCpapwKvoBWJglUpNL/JEpXhbU3pQ4qAuymarQLqvcjCo9euQYksf18lCzT0eThbGO+ywMTxEGQa94GDYSPsUs/yYmg0+GUyXCt3r629YhKFZk/bp2zk3SokuDZgXf/Gq4O/JobYJdP85hVf+7qaPc5inE/XzaYrbm4Oo3U33K6upADX3GDpzZpIy3aSBRUlbLVntDcoTubV1TbHlw3yPWBDbYgS79YMp7d+A9w7NY2Rc/eg/aM2IjL+vwVuZBqMGjfRJy9UX5DGh/IDLegdj+KFCkrF+CN6pj+iFd0wa+RhA6rRtEdCgcoPYWR4j6R+JJIeL0S3v8SfOB4jU/qVamovC3ev4/eMTcKV4CEo2uR5En8rtmlzIXC/EtY=----ATTACHMENT:----OTcyNzY2OTgzOTI1MTY5NyAxNDcwNTMyNjEzNDA5NzIyIDk0NTg5MzM4OTg0MDEzNjM=