1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Conia\Cli; |
||
6 | |||
7 | class Commands |
||
8 | { |
||
9 | protected array $commands = []; |
||
10 | |||
11 | 21 | public function __construct(Command|array $commands = []) |
|
12 | { |
||
13 | 21 | $this->add($commands); |
|
14 | } |
||
15 | |||
16 | 21 | public function add(Commands|Command|array $commands): void |
|
17 | { |
||
18 | 21 | if (is_array($commands)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
19 | 19 | foreach ($commands as $command) { |
|
20 | 18 | $this->add($command); |
|
21 | } |
||
22 | 21 | } elseif ($commands instanceof Commands) { |
|
23 | 2 | foreach ($commands->get() as $command) { |
|
24 | 2 | $this->addCommand($command); |
|
25 | } |
||
26 | } else { |
||
27 | 21 | $this->addCommand($commands); |
|
28 | } |
||
29 | } |
||
30 | |||
31 | 21 | public function get(): array |
|
32 | { |
||
33 | 21 | return $this->commands; |
|
34 | } |
||
35 | |||
36 | 21 | protected function addCommand(Command $command): void |
|
37 | { |
||
38 | 21 | $this->commands[] = $command; |
|
39 | } |
||
40 | } |
||
41 |