Permalink
Browse files

feature #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
  • Loading branch information...
fabpot committed Oct 3, 2017
2 parents ed57e74 + 9011f47 commit dcca1804f5da09b76e08cd50d2875d9565e78960
@@ -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
-----
@@ -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 @@ 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),
@@ -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)
@@ -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;
}
}

0 comments on commit dcca180

Please sign in to comment.