8000 [DependencyInjection] resolve env variables by jderusse · Pull Request #31000 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] resolve env variables #31000

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ protected function load($file)
*
* @throws EnvNotFoundException When the environment variable is not found and has no default value
*/
protected function getEnv($name)
public function getEnv($name)
{
if (isset($this->resolving[$envName = "env($name)"])) {
throw new ParameterCircularReferenceException(array_keys($this->resolving));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ public static function hash($value)
/**
* {@inheritdoc}
*/
protected function getEnv($name)
public function getEnv($name)
{
$value = parent::getEnv($name);
$bag = $this->getParameterBag();
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ public function getEnv($prefix, $name, \Closure $getEnv)
if (!isset($match[1])) {
return '%';
}
$value = $this->container->getParameter($match[1]);

$subEnv = $match[1];
if ($this->container instanceof Container) {
if (0 === strpos($subEnv, 'env(') && ')' === substr($subEnv, -1) && 'env()' !== $subEnv) {
$subEnv = substr($subEnv, 4, -1);
}

$value = $this->container->getEnv($subEnv);
} else {
$value = $this->container->getParameter($subEnv);
}
if (!is_scalar($value)) {
throw new RuntimeException(sprintf('Parameter "%s" found when resolving env var "%s" must be scalar, "%s" given.', $match[1], $name, \gettype($value)));
}
Expand Down
0