-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathShowCommand.php
61 lines (53 loc) · 1.88 KB
/
ShowCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Psecio\Iniscan\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class ShowCommand extends Command
{
protected function configure()
{
$this->setName('show')
->setDescription('Show the current PHP configuration')
->setDefinition(array(
new InputOption('path', 'path', InputOption::VALUE_OPTIONAL, 'Path to the php.ini')
))
->setHelp(
'Execute the scan on the php.ini to show current settings'
);
}
/**
* Execute the "show" command
*
* @param InputInterface $input Input object
* @param OutputInterface $output Output object
* @throws \Exception
* @return null
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$ini = parse_ini_file($path, true);
$output->writeLn('Current PHP.ini settings from '.$path);
$output->writeLn('##########');
foreach ($ini as $section => $data) {
$output->writeLn('<info>:: '.$section.'</info>');
if (empty($data)) {
$output->writeLn("\t<fg=yellow>No settings</fg=yellow>");
} else {
foreach ($data as $path => $value) {
$output->writeLn("\t".$path.' => '.var_export($value, true));
}
}
$output->writeLn("-----------------\n");
}
}
}