|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Platine\Framework\Demo\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Platine\Config\Config; |
|
12
|
|
|
use Platine\Console\Command\Command; |
|
13
|
|
|
use Platine\Framework\App\Application; |
|
14
|
|
|
use Platine\Stdlib\Helper\Str; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Description of ConfigCommand |
|
18
|
|
|
* |
|
19
|
|
|
* @author tony |
|
20
|
|
|
*/ |
|
21
|
|
|
class ConfigCommand extends Command |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
protected Application $application; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(Application $application) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct('config', 'Command to manage configuration'); |
|
32
|
|
|
$this->setAlias('c'); |
|
33
|
|
|
|
|
34
|
|
|
$this->addArgument('list', 'List the configuration'); |
|
35
|
|
|
$this->addOption('-t|--type', 'Configuration type', 'app', true); |
|
36
|
|
|
|
|
37
|
|
|
$this->application = $application; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function execute() |
|
41
|
|
|
{ |
|
42
|
|
|
if ($this->getArgumentValue('list')) { |
|
43
|
|
|
$this->showConfigList(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function showConfigList(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$writer = $this->io()->writer(); |
|
50
|
|
|
/** @template T @var Config<T> $config */ |
|
51
|
|
|
$config = $this->application->get(Config::class); |
|
52
|
|
|
$type = $this->getOptionValue('type'); |
|
53
|
|
|
|
|
54
|
|
|
$writer->blackBgBlue(sprintf('Show configuration for [%s]', $type), true)->eol(); |
|
55
|
|
|
|
|
56
|
|
|
$items = (array) $config->get($type, []); |
|
|
|
|
|
|
57
|
|
|
/** @var array<int, array<int, array<string, string>>> $rows*/ |
|
58
|
|
|
$rows = []; |
|
59
|
|
|
foreach ($items as $name => $value) { |
|
60
|
|
|
$valueStr = Str::stringify($value); |
|
61
|
|
|
if (is_int($name)) { |
|
62
|
|
|
$rows[] = [ |
|
63
|
|
|
'value' => $valueStr |
|
64
|
|
|
]; |
|
65
|
|
|
} else { |
|
66
|
|
|
$rows[] = [ |
|
67
|
|
|
'name' => $name, |
|
68
|
|
|
'value' => $valueStr |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$writer->table($rows); |
|
74
|
|
|
|
|
75
|
|
|
$writer->green('Command finished successfully')->eol(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|