|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Cecil\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
|
|
16
|
|
|
class CommandShowConfig extends Command |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this |
|
24
|
|
|
->setName('show:config') |
|
25
|
|
|
->setDescription('Show configuration') |
|
26
|
|
|
->setDefinition( |
|
27
|
|
|
new InputDefinition([ |
|
28
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'), |
|
29
|
|
|
]) |
|
30
|
|
|
) |
|
31
|
|
|
->setHelp('Show Website configuration.'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
38
|
|
|
{ |
|
39
|
|
|
try { |
|
40
|
|
|
$output->writeln($this->printArray($this->getBuilder($output)->getConfig()->getAsArray())); |
|
41
|
|
|
} catch (\Exception $e) { |
|
42
|
|
|
throw new \Exception(sprintf($e->getMessage())); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return 0; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Print an array in console. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array $array |
|
52
|
|
|
* @param int $column |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
private function printArray($array, $column = -2) |
|
55
|
|
|
{ |
|
56
|
|
|
$output = ''; |
|
57
|
|
|
|
|
58
|
|
|
if (is_array($array)) { |
|
59
|
|
|
$column += 2; |
|
60
|
|
|
foreach ($array as $key => $val) { |
|
61
|
|
|
if (is_array($val)) { |
|
62
|
|
|
$output .= str_repeat(' ', $column) . "$key:\n" . $this->printArray($val, $column); |
|
63
|
|
|
} |
|
64
|
|
|
if (is_string($val) || is_int($val)) { |
|
65
|
|
|
$output .= str_repeat(' ', $column) . "$key: $val\n"; |
|
66
|
|
|
} |
|
67
|
|
|
if (is_bool($val)) { |
|
68
|
|
|
$output .= str_repeat(' ', $column) . "$key: " . ($val ? 'true' : 'false') . "\n"; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $output; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|