-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConsoleApplication.php
More file actions
46 lines (34 loc) · 1.13 KB
/
ConsoleApplication.php
File metadata and controls
46 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace CodedMonkey\Dirigent;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class ConsoleApplication extends Application
{
private bool $commandsRegistered = false;
public function __construct(
private KernelInterface $kernel,
) {
parent::__construct('Dirigent', Kernel::VERSION);
}
public function doRun(InputInterface $input, OutputInterface $output): int
{
$this->registerCommands();
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
return parent::doRun($input, $output);
}
private function registerCommands(): void
{
if ($this->commandsRegistered) {
return;
}
$this->commandsRegistered = true;
$this->kernel->boot();
$container = $this->kernel->getContainer();
$commands = $container->get('dirigent_command_locator');
foreach ($commands as $command) {
$this->add($command);
}
}
}