Add checking when adding a stage class string
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user