Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #23940 [DI] Fix resolving env vars when compiling a ContainerBuil…
…der (nicolas-grekas) This PR was merged into the 3.3 branch. Discussion ---------- [DI] Fix resolving env vars when compiling a ContainerBuilder | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As spotted by @ro0NL, `$container->compile(true)` doesn't resolve direct env var references found in service definitions. Fixed here. Commits ------- 9219594 [DI] Fix resolving env vars when compiling a ContainerBuilder
- Loading branch information
Showing
5 changed files
with
120 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* Replaces env var placeholders by their current values. | ||
*/ | ||
class ResolveEnvPlaceholdersPass extends AbstractRecursivePass | ||
{ | ||
protected function processValue($value, $isRoot = false) | ||
{ | ||
if (is_string($value)) { | ||
return $this->container->resolveEnvPlaceholders($value, true); | ||
} | ||
if ($value instanceof Definition) { | ||
$changes = $value->getChanges(); | ||
if (isset($changes['class'])) { | ||
$value->setClass($this->container->resolveEnvPlaceholders($value->getClass(), true)); | ||
} | ||
if (isset($changes['file'])) { | ||
$value->setFile($this->container->resolveEnvPlaceholders($value->getFile(), true)); | ||
} | ||
} | ||
|
||
$value = parent::processValue($value, $isRoot); | ||
|
||
if ($value && is_array($value)) { | ||
$value = array_combine($this->container->resolveEnvPlaceholders(array_keys($value), true), $value); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters