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