Add checking when adding a stage class string

This commit is contained in:
Tim
2025-08-28 23:01:16 +02:00
parent 95adf23306
commit a5b6d2982b

View File

@ -22,7 +22,13 @@ class OptionsStageBuilder
public function add(string|OptionsStageInterface $stageClass): self
{
if (is_string($stageClass)) {
$this->stages[] = $this->bag->get($stageClass);
if (new \ReflectionClass($stageClass)->implementsInterface(OptionsStageInterface::class)) {
$this->stages[] = $this->bag->get($stageClass);
} else {
throw new \InvalidArgumentException(
sprintf('Stage must be an instance of OptionsStageInterface, %s given', get_debug_type($stage))
);
}
} else {
$this->stages[] = $stageClass;
}
@ -41,4 +47,4 @@ class OptionsStageBuilder
{
return new ItemsOptionsPipeline(new OptionsProcessor($this->options), ...$this->stages);
}
}
}