1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace pjpawel\LightApi\Command\Internal; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use pjpawel\LightApi\Command\Input\InputInterface; |
7
|
|
|
use pjpawel\LightApi\Command\Output\OutputInterface; |
8
|
|
|
use pjpawel\LightApi\Kernel; |
9
|
|
|
use ReflectionClass; |
10
|
|
|
|
11
|
|
|
class DebugCommand extends KernelAwareCommand |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
private const COMPONENTS = [ |
15
|
|
|
'container' => 'containerLoader', |
16
|
|
|
'router' => 'router', |
17
|
|
|
'commands' => 'commandLoader' |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
public function prepare(InputInterface $input): void |
21
|
|
|
{ |
22
|
|
|
$input->addArgument('component', description: 'Component to get info about. There is container, router, command'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param InputInterface $input |
27
|
|
|
* @param OutputInterface $output |
28
|
|
|
* @return int |
29
|
|
|
* @throws Exception |
30
|
|
|
*/ |
31
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int |
32
|
|
|
{ |
33
|
|
|
$component = $input->getArgument('component'); |
34
|
|
|
if (!array_key_exists($component, self::COMPONENTS)) { |
35
|
|
|
throw new Exception('Invalid component'); |
36
|
|
|
} |
37
|
|
|
$reflectionClass = new ReflectionClass(Kernel::class); |
38
|
|
|
$reflectionProperty = $reflectionClass->getProperty(self::COMPONENTS[$component]); |
39
|
|
|
$value = $reflectionProperty->getValue($this->kernel); |
40
|
|
|
$toShow = match ($component) { |
41
|
|
|
'container' => $value->definitions, |
42
|
|
|
'router' => $value->routes, |
43
|
|
|
'commands' => $value->command |
44
|
|
|
}; |
45
|
|
|
$output->write(var_export($toShow, true)); |
46
|
|
|
return self::SUCCESS; |
47
|
|
|
} |
48
|
|
|
} |