1 | <?php |
||
28 | class ConfigCommandHandler |
||
29 | { |
||
30 | /** |
||
31 | * @var RootModuleFileManager |
||
32 | */ |
||
33 | private $manager; |
||
34 | |||
35 | /** |
||
36 | * Creates the handler. |
||
37 | * |
||
38 | * @param RootModuleFileManager $manager The root module file manager |
||
39 | */ |
||
40 | 18 | public function __construct(RootModuleFileManager $manager) |
|
41 | { |
||
42 | 18 | $this->manager = $manager; |
|
43 | 18 | } |
|
44 | |||
45 | /** |
||
46 | * Handles the "config" command. |
||
47 | * |
||
48 | * @param Args $args The console arguments |
||
49 | * @param IO $io The I/O |
||
50 | * |
||
51 | * @return int The status code |
||
52 | */ |
||
53 | 6 | public function handleList(Args $args, IO $io) |
|
54 | { |
||
55 | 6 | $raw = !$args->isOptionSet('parsed'); |
|
56 | 6 | $userValues = $this->manager->getConfigKeys(false, false, $raw); |
|
57 | 6 | $effectiveValues = $this->manager->getConfigKeys(true, true, $raw); |
|
58 | |||
59 | 6 | $table = new Table(PuliTableStyle::borderless()); |
|
60 | 6 | $table->setHeaderRow(array('Config Key', 'User Value', 'Effective Value')); |
|
61 | |||
62 | 6 | foreach ($effectiveValues as $key => $value) { |
|
63 | 6 | $table->addRow(array( |
|
64 | 6 | sprintf('<c1>%s</c1>', $key), |
|
65 | 6 | array_key_exists($key, $userValues) |
|
66 | 6 | ? StringUtil::formatValue($userValues[$key], false) |
|
67 | 6 | : '', |
|
68 | 6 | StringUtil::formatValue($value, false), |
|
69 | )); |
||
70 | } |
||
71 | |||
72 | 6 | $table->render($io); |
|
73 | |||
74 | 6 | return 0; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Handles the "config <key>" command. |
||
79 | * |
||
80 | * @param Args $args The console arguments |
||
81 | * @param IO $io The I/O |
||
82 | * |
||
83 | * @return int The status code |
||
84 | */ |
||
85 | 6 | public function handleShow(Args $args, IO $io) |
|
86 | { |
||
87 | 6 | $raw = !$args->isOptionSet('parsed'); |
|
88 | 6 | $value = $this->manager->getConfigKey($args->getArgument('key'), null, true, $raw); |
|
89 | |||
90 | 6 | $io->writeLine(StringUtil::formatValue($value, false)); |
|
91 | |||
92 | 6 | return 0; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * Handles the "config <key> <value>" command. |
||
97 | * |
||
98 | * @param Args $args The console arguments |
||
99 | * |
||
100 | * @return int The status code |
||
101 | */ |
||
102 | 5 | public function handleSet(Args $args) |
|
103 | { |
||
104 | 5 | $value = StringUtil::parseValue($args->getArgument('value')); |
|
105 | |||
106 | 5 | $this->manager->setConfigKey($args->getArgument('key'), $value); |
|
107 | |||
108 | 5 | return 0; |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * Handles the "config -r <key>" command. |
||
113 | * |
||
114 | * @param Args $args The console arguments |
||
115 | * |
||
116 | * @return int The status code |
||
117 | */ |
||
118 | 1 | public function handleReset(Args $args) |
|
124 | } |
||
125 |