From 9011f47e8fcc29a07b8895c40185836b63f277b3 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 10 Sep 2017 15:11:38 +0200 Subject: [PATCH] [FrameworkBundle] Expose dotenv in bin/console about --- .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../FrameworkBundle/Command/AboutCommand.php | 42 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index f49eb6dbc2dd3..49fd03165a5b7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -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 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php index 4a594d3ae70ce..3c5ba3e93d3cf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php @@ -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 %command.name% command displays information about the current Symfony project. + +The PHP section displays important configuration that could affect your application. The values might +be different between web and CLI. + +The Environment 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 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var $kernel KernelInterface */ $kernel = $this->getApplication()->getKernel(); - $io->table(array(), array( + $rows = array( array('Symfony'), new TableSeparator(), array('Version', Kernel::VERSION), @@ -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('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 @@ 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) { + if ('' !== $name && false !== $value = getenv($name)) { + $vars[$name] = $value; + } + } + + return $vars; + } }