|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author jan huang <[email protected]> |
|
4
|
|
|
* @copyright 2016 |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://www.github.com/janhuang |
|
7
|
|
|
* @link http://www.fast-d.cn/ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace FastD\Console; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use FastD\Utils\FileObject; |
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Config |
|
23
|
|
|
* @package FastD\Console |
|
24
|
|
|
*/ |
|
25
|
|
|
class ConfigDump extends Command |
|
26
|
|
|
{ |
|
27
|
|
|
public function configure() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->setName('config:dump'); |
|
30
|
|
|
$this->addArgument('name', InputArgument::OPTIONAL, 'file name'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param InputInterface $input |
|
35
|
|
|
* @param OutputInterface $output |
|
36
|
|
|
* @return mixed |
|
37
|
|
|
*/ |
|
38
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
39
|
|
|
{ |
|
40
|
|
|
if ($input->getArgument('name')) { |
|
41
|
|
|
$file = app()->getPath() . '/config/' . $input->getArgument('name') . '.php'; |
|
42
|
|
|
$file = str_replace('.php.php', '.php', $file); |
|
43
|
|
|
$config = load($file); |
|
44
|
|
|
$output->write('<comment>' . Yaml::dump($config) . '</comment>'); |
|
45
|
|
|
return 0; |
|
46
|
|
|
} |
|
47
|
|
|
$table = new Table($output); |
|
48
|
|
|
$rows = []; |
|
49
|
|
|
$table->setHeaders(array('File', 'Config', 'Owner', 'Modify At',)); |
|
50
|
|
|
|
|
51
|
|
|
foreach (glob(app()->getPath() . '/config/*') as $file) { |
|
52
|
|
|
$file = new FileObject($file); |
|
53
|
|
|
$config = load($file->getPathname()); |
|
54
|
|
|
$count = 0; |
|
55
|
|
|
if (is_array($config)) { |
|
56
|
|
|
$count = count(array_keys($config)); |
|
57
|
|
|
} |
|
58
|
|
|
$rows[] = [ |
|
59
|
|
|
$file->getFilename(), |
|
60
|
|
|
$count . ' Keys', |
|
61
|
|
|
posix_getpwuid($file->getOwner())['name'], |
|
62
|
|
|
date('Y-m-d H:i:s', $file->getMTime()), |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$table->setRows($rows); |
|
67
|
|
|
$table->render(); |
|
68
|
|
|
} |
|
69
|
|
|
} |