Skip to content

Commit b2edd51

Browse files
bug symfony#24850 [DI] Fix cannot bind env var (ogizanagi)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Fix cannot bind env var | Q | A | ------------- | --- | Branch? | 3.4 <!-- see comment below --> | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | symfony#24845 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A In symfony#24602 we removed the processing of bindings from the `AbstractRecursivePass`. But there is actually one case where we want a recursive pass to process them: to resolve env param placeholders. Commits ------- f8f3a15 [DI] Fix cannot bind env var
2 parents 69b48d0 + f8f3a15 commit b2edd51

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected function processValue($value, $isRoot = false)
6666
return $this->resolveArrays || !$v || !is_array($v) ? $v : $value;
6767
}
6868
if ($value instanceof Definition) {
69+
$value->setBindings($this->processValue($value->getBindings()));
6970
$changes = $value->getChanges();
7071
if (isset($changes['class'])) {
7172
$value->setClass($this->bag->resolveValue($value->getClass()));

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function testAliasParametersShouldBeResolved()
6464
$this->assertSame('foo', $this->container->getAlias('bar')->__toString());
6565
}
6666

67+
public function testBindingsShouldBeResolved()
68+
{
69+
list($boundValue) = $this->container->getDefinition('foo')->getBindings()['$baz']->getValues();
70+
71+
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
72+
}
73+
6774
private function createContainerBuilder()
6875
{
6976
$containerBuilder = new ContainerBuilder();
@@ -84,6 +91,7 @@ private function createContainerBuilder()
8491
$fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
8592
$fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
8693
$fooDefinition->setFile('%foo.file%');
94+
$fooDefinition->setBindings(array('$baz' => '%env(BAZ)%'));
8795

8896
$containerBuilder->setAlias('%alias.id%', 'foo');
8997

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct()
2929

3030
$this->services = array();
3131
$this->methodMap = array(
32+
'bar' => 'getBarService',
3233
'test' => 'getTestService',
3334
);
3435

@@ -60,6 +61,16 @@ public function isFrozen()
6061
return true;
6162
}
6263

64+
/**
65+
* Gets the public 'bar' shared service.
66+
*
67+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
68+
*/
69+
protected function getBarService()
70+
{
71+
return $this->services['bar'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\Bar($this->getEnv('QUZ'));
72+
}
73+
6374
/**
6475
* Gets the public 'test' shared service.
6576
*

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services26.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ services:
1515
- '%env(Bar)%'
1616
- 'foo%bar%baz'
1717
- '%baz%'
18+
bar:
19+
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
20+
public: true
21+
bind:
22+
$quz: '%env(QUZ)%'

0 commit comments

Comments
 (0)