1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slack-cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Cas Leentfaar <[email protected]> |
7
|
|
|
* |
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 CL\SlackCli\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Cas Leentfaar <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class ConfigListCommand extends AbstractCommand |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritDoc} |
24
|
|
|
*/ |
25
|
1 |
|
protected function configure() |
26
|
|
|
{ |
27
|
1 |
|
parent::configure(); |
28
|
|
|
|
29
|
1 |
|
$this->setName('config:list'); |
30
|
1 |
|
$this->setDescription('Lists all the keys and values from the global configuration'); |
31
|
1 |
|
$this->setHelp(<<<EOT |
32
|
|
|
The <info>config:list</info> command lists all the keys and values from the global configuration. |
33
|
|
|
EOT |
34
|
1 |
|
); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
41
|
|
|
{ |
42
|
1 |
|
$rows = $this->extractConfiguration($this->getConfig()->all(), $this->getConfig()->raw(), $output); |
43
|
|
|
|
44
|
1 |
|
$this->createKeyValueTable($rows)->render(); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Extracts the contents of the configuration file recursively |
49
|
|
|
* |
50
|
|
|
* @param array $contents |
51
|
|
|
* @param array $rawContents |
52
|
|
|
* @param OutputInterface $output |
53
|
|
|
* @param string|null $k |
54
|
|
|
* @param array $currentRows |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
1 |
|
private function extractConfiguration( |
59
|
|
|
array $contents, |
60
|
|
|
array $rawContents, |
61
|
|
|
OutputInterface $output, |
62
|
|
|
$k = null, |
63
|
|
|
&$currentRows = [] |
64
|
|
|
) { |
65
|
1 |
|
$origK = $k; |
66
|
1 |
|
foreach ($contents as $key => $value) { |
67
|
1 |
|
if ($k === null && !in_array($key, array('config'))) { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
$rawVal = isset($rawContents[$key]) ? $rawContents[$key] : null; |
72
|
|
|
|
73
|
1 |
|
if (is_array($value) && (!is_numeric(key($value)))) { |
74
|
1 |
|
$k .= preg_replace('{^config\.}', '', $key . '.'); |
75
|
1 |
|
$this->extractConfiguration($value, $rawVal, $output, $k, $currentRows); |
76
|
|
|
|
77
|
1 |
|
if (substr_count($k, '.') > 1) { |
78
|
|
|
$k = str_split($k, strrpos($k, '.', -2)); |
79
|
|
|
$k = $k[0] . '.'; |
80
|
|
|
} else { |
81
|
1 |
|
$k = $origK; |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
continue; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
if (is_array($value)) { |
88
|
|
|
$value = array_map(function ($val) { |
89
|
|
|
return is_array($val) ? json_encode($val) : $val; |
90
|
|
|
}, $value); |
91
|
|
|
|
92
|
|
|
$value = '[' . implode(', ', $value) . ']'; |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
if (is_bool($value)) { |
96
|
|
|
$value = var_export($value, true); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
if (is_string($rawVal) && $rawVal != $value) { |
100
|
|
|
$currentRows[$k . $key] = $rawVal . ' (' . $value . ')'; |
101
|
|
|
} else { |
102
|
1 |
|
$currentRows[$k . $key] = $value; |
103
|
|
|
} |
104
|
1 |
|
} |
105
|
|
|
|
106
|
1 |
|
return $currentRows; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|