Skip to content

[FrameworkBundle] Expose dotenv in bin/console about #24144

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

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
42 changes: 39 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
;
}

/**
Expand All @@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var $kernel KernelInterface */
$kernel = $this->getApplication()->getKernel();

$io->table(array(), array(
$rows = array(
array('<info>Symfony</>'),
new TableSeparator(),
array('Version', Kernel::VERSION),
Expand All @@ -75,7 +87,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
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)
Expand Down Expand Up @@ -103,4 +127,16 @@ private static function isExpired($date)

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break when getenv returns false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof, explode returns an array with one empty string:

>>> explode(',', false)
=> [
     "",
   ]
>>> 

if ('' !== $name && false !== $value = getenv($name)) {
$vars[$name] = $value;
}
}

return $vars;
}
}