Skip to content

Commit dcca180

Browse files
committed
feature symfony#24144 [FrameworkBundle] Expose dotenv in bin/console about (ro0NL)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] Expose dotenv in bin/console about | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> For completeness in CLI, shown in web under "Server parameters". ```php (new Dotenv())->populate(['APP_ENV' => 'prod', 'APP_DEBUG' => '1']); ``` ![image](https://user-images.githubusercontent.com/1047696/30293203-fe360d0a-9738-11e7-80ed-94901cea8898.png) Commits ------- 9011f47 [FrameworkBundle] Expose dotenv in bin/console about
2 parents ed57e74 + 9011f47 commit dcca180

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CHANGELOG
5959
and `YamlLintCommand` classes have been marked as final
6060
* Added `asset.request_context.base_path` and `asset.request_context.secure` parameters
6161
to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters)
62+
* Display environment variables managed by `Dotenv` in `AboutCommand`
6263

6364
3.3.0
6465
-----

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@ class AboutCommand extends ContainerAwareCommand
3535
*/
3636
protected function configure()
3737
{
38-
$this->setDescription('Displays information about the current project');
38+
$this
39+
->setDescription('Displays information about the current project')
40+
->setHelp(<<<'EOT'
41+
The <info>%command.name%</info> command displays information about the current Symfony project.
42+
43+
The <info>PHP</info> section displays important configuration that could affect your application. The values might
44+
be different between web and CLI.
45+
46+
The <info>Environment</info> section displays the current environment variables managed by Symfony Dotenv. It will not
47+
be shown if no variables were found. The values might be different between web and CLI.
48+
EOT
49+
)
50+
;
3951
}
4052

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

51-
$io->table(array(), array(
63+
$rows = array(
5264
array('<info>Symfony</>'),
5365
new TableSeparator(),
5466
array('Version', Kernel::VERSION),
@@ -75,7 +87,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
7587
array('OPcache', extension_loaded('Zend OPcache') && ini_get('opcache.enable') ? 'true' : 'false'),
7688
array('APCu', extension_loaded('apcu') && ini_get('apc.enabled') ? 'true' : 'false'),
7789
array('Xdebug', extension_loaded('xdebug') ? 'true' : 'false'),
78-
));
90+
);
91+
92+
if ($dotenv = self::getDotEnvVars()) {
93+
$rows = array_merge($rows, array(
94+
new TableSeparator(),
95+
array('<info>Environment (.env)</>'),
96+
new TableSeparator(),
97+
), array_map(function ($value, $name) {
98+
return array($name, $value);
99+
}, $dotenv, array_keys($dotenv)));
100+
}
101+
102+
$io->table(array(), $rows);
79103
}
80104

81105
private static function formatPath($path, $baseDir = null)
@@ -103,4 +127,16 @@ private static function isExpired($date)
103127

104128
return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59');
105129
}
130+
131+
private static function getDotEnvVars()
132+
{
133+
$vars = array();
134+
foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {
135+
if ('' !== $name && false !== $value = getenv($name)) {
136+
$vars[$name] = $value;
137+
}
138+
}
139+
140+
return $vars;
141+
}
106142
}

0 commit comments

Comments
 (0)