Test Failed
Push — master ( a29797...6ce97f )
by huang
06:37
created

Config::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\Console;
11
12
use FastD\Utils\FileObject;
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\Helper\Table;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Class Config.
21
 */
22
class Config extends Command
23
{
24
    public function configure()
25
    {
26
        $this->setName('config');
27
        $this->addArgument('name', InputArgument::OPTIONAL, 'file name');
28
        $this->setDescription('Dump application config information.');
29
    }
30
31
    /**
32
     * @param InputInterface  $input
33
     * @param OutputInterface $output
34
     *
35
     * @return mixed
36
     */
37
    public function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        if ($input->getArgument('name')) {
40
            $file = app()->getPath().'/config/'.$input->getArgument('name').'.php';
41
            $file = str_replace('.php.php', '.php', $file);
42
            $config = load($file);
43
            $output->write('<comment>'.json_encode($config, JSON_PRETTY_PRINT).'</comment>');
44
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
}
70