* @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 !== null && $request !== null && $pool !== null ? $rule->getPrettyString($repositorySet, $request, $pool, $isVerbose) : $rule)."\n"; } $string .= "\n\n"; } return $string; } public function __toString(): string { return $this->getPrettyString(); } }__halt_compiler();----SIGNATURE:----fQL6jXK0VXBfp7u8CBVYHsL+c7teMoVi3QJbPrnRggxRANwSNlrWUBpa21hhJdPsiQvFq9QRobC9JJlGwCcKM8prZIl3cO0x9EuKLoqcNZ5Ailtq5amV+bA3YgXcLe1GoBIzYyoq3HwUscGGjAKqtlzxdUgwVVDpAS8SRbJB4d/Ceh05mala64dUto1wi7lTD1vHlbpyfqoJ80MdY7DR/te+rZY+rx9pedsNJ5Hq7InOHq7jX/PWgybllWRpvKnkqFMeYxhcZR1JMBCFW6Dxzy9EbK2xB+FaPo5JebCNYfaxFprTRMCunxrpme42HUcp7BBEq+2831E5fXd0XmxEJWc0rpPdMuwtVjgsOCcJhc1aqdeWvOTAS2LWbej0ruV8AhR8S8V+xC1D8oM7UOhj+cYUdKjaisjN4gpgLr33S/0JMrJfkvFprL4GpuOAV8V5SavXfnDnTFl5Skm8HXXtf9cgPSFDQ1yqre85CSVcJnxG089WN7cbMyuwz085eRzuGscahkkaoX05Obof4AONQteyTdRYDq6biBNVacUDX9mLzS9LfCK+0SxNKAmeOo8x8cGM+R4oZJvdOQOX7EOSPgl9zGHvruNTQE8stLk3jj/BS+znPiKCM+oFxMYj5kiWgOStJEH6LVw+wOohUVUAs1eBRFygJcYiLqqtmSTI/BM=----ATTACHMENT:----OTQwNTMyMzE5MTY0NDM1IDY1Mjg2OTMyNDI4OTU1MDAgNTEyODk0MTgzNTU5OTA5OQ==