8000 [DependencyInjection] resolve env variables · symfony/symfony@c617680 · GitHub
[go: up one dir, main page]

Skip to content

Commit c617680

Browse files
committed
[DependencyInjection] resolve env variables
1 parent b30f57e commit c617680

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ protected function load($file)
461461
*
462462
* @throws EnvNotFoundException When the environment variable is not found and has no default value
463463
*/
464-
protected function getEnv($name)
464+
public function getEnv($name)
465465
{
466466
if (isset($this->resolving[$envName = "env($name)"])) {
467467
throw new ParameterCircularReferenceException(array_keys($this->resolving));

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ public static function hash($value)
15691569
/**
15701570
* {@inheritdoc}
15711571
*/
1572-
protected function getEnv($name)
1572+
public function getEnv($name)
15731573
{
15741574
$value = parent::getEnv($name);
15751575
$bag = $this->getParameterBag();

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,17 @@ public function getEnv($prefix, $name, \Closure $getEnv)
140140
if (!isset($match[1])) {
141141
return '%';
142142
}
143-
$value = $this->container->getParameter($match[1]);
143+
144+
$subEnv = $match[1];
145+
if ($container instanceof Container) {
146+
if (0 === strpos($subEnv, 'env(') && ')' === substr($subEnv, -1) && 'env()' !== $subEnv) {
147+
$subEnv = substr($subEnv, 4, -1);
148+
}
149+
150+
$value = $this->container->getEnv($subEnv);
151+
} else {
152+
$value = $this->container->getParameter($subEnv);
153+
}
144154
if (!is_scalar($value)) {
145155
throw new RuntimeException(sprintf('Parameter "%s" found when resolving env var "%s" must be scalar, "%s" given.', $match[1], $name, \gettype($value)));
146156
}

0 commit comments

Comments
 (0)
0