Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix show command for PHP >= 7.0.0 #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions src/Psecio/Iniscan/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,52 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}

$this->showIni($output, $path);
}

/**
* Read an INI file and display each of it's configuration
*
* @param OutputInterface $output Output object
* @param string $path The path to the ini file
*
* @return null
*/
protected function showIni(OutputInterface $output, $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));
}
}
$this->showSection($output, $data);
$output->writeLn("-----------------\n");
}

}

/**
* Display a section from the INI file
*
* @param OutputInterface $output Output object
* @param mixed $data The content of the section
*
* @return null
*/
protected function showSection(OutputInterface $output, $data)
{
if (empty($data)) {
$output->writeLn("\t<fg=yellow>No settings</fg=yellow>");
return;
} else if (is_array($data)) {
foreach ($data as $path => $value) {
$output->writeLn("\t".$path.' => '.var_export($value, true));
}
return;
}
$output->writeLn("\t" . var_export($data, true));
}
}