| 1 | <?php declare(strict_types = 1); |
||
| 15 | class CommandCollection implements CommandCollectionContract |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var string[] |
||
| 19 | */ |
||
| 20 | protected $commands = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @inheritDoc |
||
| 24 | */ |
||
| 25 | public function add(string $commandClass) |
||
| 26 | { |
||
| 27 | if (!is_subclass_of($commandClass, Command::class)) { |
||
| 28 | throw new InvalidArgumentException( |
||
| 29 | sprintf('Provided command "%s" is not subclass of "%s" class.', $commandClass, Command::class) |
||
| 30 | ); |
||
| 31 | } |
||
| 32 | $this->commands[] = $commandClass; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritDoc |
||
| 37 | */ |
||
| 38 | public function all(): array |
||
| 39 | { |
||
| 40 | return array_unique($this->commands); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @inheritDoc |
||
| 45 | */ |
||
| 46 | public function getIterator() |
||
| 50 | } |