1 | <?php |
||
2 | |||
3 | namespace Elgg; |
||
4 | |||
5 | use Elgg\Cli\Command; |
||
6 | use Symfony\Component\Console\Application as ConsoleApplication; |
||
7 | |||
8 | /** |
||
9 | * CLI bootstrap |
||
10 | */ |
||
11 | class Cli { |
||
12 | |||
13 | /** |
||
14 | * @var ConsoleApplication |
||
15 | */ |
||
16 | protected $console; |
||
17 | |||
18 | /** |
||
19 | * @var HooksRegistrationService |
||
20 | */ |
||
21 | protected $hooks; |
||
22 | |||
23 | /** |
||
24 | * Constructor |
||
25 | * |
||
26 | * @param ConsoleApplication $console Console application instance |
||
27 | * @param HooksRegistrationService $hooks Hooks registration service |
||
28 | */ |
||
29 | 1 | public function __construct(ConsoleApplication $console, HooksRegistrationService $hooks) { |
|
30 | 1 | $this->console = $console; |
|
31 | 1 | $this->hooks = $hooks; |
|
32 | 1 | } |
|
33 | |||
34 | /** |
||
35 | * Add CLI tools to the console application |
||
36 | * @return void |
||
37 | */ |
||
38 | protected function bootstrap() { |
||
39 | $commands = $this->hooks->trigger('commands', 'cli', null, []); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
40 | foreach ($commands as $command) { |
||
41 | if (class_exists($command) && is_subclass_of($command, Command::class)) { |
||
42 | $this->console->add(new $command()); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Bootstrap and run console application |
||
49 | * @return void |
||
50 | */ |
||
51 | public function run() { |
||
52 | $this->bootstrap(); |
||
53 | $this->console->run(); |
||
54 | } |
||
55 | |||
56 | } |
||
57 |