[^\']+)\')|(?[^\s]+)#'; /** * @var string */ protected $name; /** * @var string[] */ protected $instructions = []; /** * @var string[] */ protected $sources = []; public function __construct(string $name, string $rule) { $this->name = $name; if (preg_match_all(self::RULE_PATTERN, $rule, $matches)) { foreach (array_keys($matches[0]) as $index) { if ($matches['instruction'][$index] !== '') { $this->instructions[] = $matches['instruction'][$index]; } elseif ($matches['source'][$index] !== '') { $this->sources[] = $matches['source'][$index]; } } } } public function getName(): string { return $this->name; } /** * @return string[] */ public function getInstructions(): array { return $this->instructions; } /** * @return string[] */ public function getSources(): array { return $this->sources; } public function hasInstructions(string ...$instructions): bool { return array_intersect($this->instructions, $instructions) !== []; } }