[FrameworkBundle] Expose dotenv in bin/console about

This commit is contained in:
Roland Franssen 2017-09-10 15:11:38 +02:00
parent ed57e748dc
commit 9011f47e8f
2 changed files with 40 additions and 3 deletions

View File

@ -59,6 +59,7 @@ CHANGELOG
and `YamlLintCommand` classes have been marked as final
* Added `asset.request_context.base_path` and `asset.request_context.secure` parameters
to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters)
* Display environment variables managed by `Dotenv` in `AboutCommand`
3.3.0
-----

View File

@ -35,7 +35,19 @@ class AboutCommand extends ContainerAwareCommand
*/
protected function configure()
{
$this->setDescription('Displays information about the current project');
$this
->setDescription('Displays information about the current project')
->setHelp(<<<'EOT'
The <info>%command.name%</info> command displays information about the current Symfony project.
The <info>PHP</info> section displays important configuration that could affect your application. The values might
be different between web and CLI.
The <info>Environment</info> section displays the current environment variables managed by Symfony Dotenv. It will not
be shown if no variables were found. The values might be different between web and CLI.
EOT
)
;
}
/**
@ -48,7 +60,7 @@ class AboutCommand extends ContainerAwareCommand
/** @var $kernel KernelInterface */
$kernel = $this->getApplication()->getKernel();
$io->table(array(), array(
$rows = array(
array('<info>Symfony</>'),
new TableSeparator(),
array('Version', Kernel::VERSION),
@ -75,7 +87,19 @@ class AboutCommand extends ContainerAwareCommand
array('OPcache', extension_loaded('Zend OPcache') && ini_get('opcache.enable') ? 'true' : 'false'),
array('APCu', extension_loaded('apcu') && ini_get('apc.enabled') ? 'true' : 'false'),
array('Xdebug', extension_loaded('xdebug') ? 'true' : 'false'),
));
);
if ($dotenv = self::getDotEnvVars()) {
$rows = array_merge($rows, array(
new TableSeparator(),
array('<info>Environment (.env)</>'),
new TableSeparator(),
), array_map(function ($value, $name) {
return array($name, $value);
}, $dotenv, array_keys($dotenv)));
}
$io->table(array(), $rows);
}
private static function formatPath($path, $baseDir = null)
@ -103,4 +127,16 @@ class AboutCommand extends ContainerAwareCommand
return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59');
}
private static function getDotEnvVars()
{
$vars = array();
foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {
if ('' !== $name && false !== $value = getenv($name)) {
$vars[$name] = $value;
}
}
return $vars;
}
}