|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Thunder micro CLI framework. |
|
7
|
|
|
* (c) Jérémy Marodon <[email protected]> |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace RxThunder\Core; |
|
13
|
|
|
|
|
14
|
|
|
use RxThunder\Core\Kernel\KernelInterface; |
|
15
|
|
|
use Silly\Application as BaseApplication; |
|
16
|
|
|
use Silly\Input\InputOption; |
|
17
|
|
|
|
|
18
|
|
|
class Application extends BaseApplication |
|
19
|
|
|
{ |
|
20
|
1 |
|
public function __construct(KernelInterface $kernel) |
|
21
|
|
|
{ |
|
22
|
1 |
|
$kernel_class = \get_class($kernel); |
|
23
|
1 |
|
$kernel->boot(); |
|
24
|
|
|
|
|
25
|
1 |
|
parent::__construct($kernel_class::NAME, $kernel_class::VERSION); |
|
26
|
|
|
|
|
27
|
1 |
|
$container = $kernel->getContainer(); |
|
28
|
1 |
|
$this->useContainer($container); |
|
29
|
|
|
|
|
30
|
1 |
|
$this->getDefinition()->addOptions([ |
|
31
|
1 |
|
new InputOption( |
|
32
|
1 |
|
'--env', |
|
33
|
1 |
|
'-e', |
|
34
|
1 |
|
InputOption::VALUE_OPTIONAL, |
|
35
|
1 |
|
'The environment name', |
|
36
|
1 |
|
$kernel->getEnvironment() |
|
37
|
|
|
), |
|
38
|
|
|
]); |
|
39
|
|
|
|
|
40
|
|
|
/** @psalm-var array<class-string, array<string, string>> $console_services_list */ |
|
41
|
1 |
|
$console_services_list = $container->findTaggedServiceIds('console'); |
|
42
|
|
|
|
|
43
|
1 |
|
foreach ($console_services_list as $id => $tag) { |
|
44
|
1 |
|
$this->registerConsole($id); |
|
45
|
|
|
} |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param class-string $console_class |
|
|
|
|
|
|
50
|
|
|
*/ |
|
51
|
1 |
|
private function registerConsole(string $console_class): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this |
|
54
|
1 |
|
->command($console_class::$expression, $console_class) |
|
|
|
|
|
|
55
|
1 |
|
->descriptions($console_class::$description, $console_class::$arguments_and_options) |
|
|
|
|
|
|
56
|
1 |
|
->defaults($console_class::$defaults); |
|
|
|
|
|
|
57
|
1 |
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|