[DI] Fix cannot bind env var

This commit is contained in:
Maxime Steinhausser 2017-11-07 09:01:11 +01:00
parent 73982760f7
commit f8f3a15b7a
4 changed files with 25 additions and 0 deletions

View File

@ -66,6 +66,7 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
return $this->resolveArrays || !$v || !is_array($v) ? $v : $value;
}
if ($value instanceof Definition) {
$value->setBindings($this->processValue($value->getBindings()));
$changes = $value->getChanges();
if (isset($changes['class'])) {
$value->setClass($this->bag->resolveValue($value->getClass()));

View File

@ -64,6 +64,13 @@ class ResolveParameterPlaceHoldersPassTest extends TestCase
$this->assertSame('foo', $this->container->getAlias('bar')->__toString());
}
public function testBindingsShouldBeResolved()
{
list($boundValue) = $this->container->getDefinition('foo')->getBindings()['$baz']->getValues();
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
}
private function createContainerBuilder()
{
$containerBuilder = new ContainerBuilder();
@ -84,6 +91,7 @@ class ResolveParameterPlaceHoldersPassTest extends TestCase
$fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
$fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
$fooDefinition->setFile('%foo.file%');
$fooDefinition->setBindings(array('$baz' => '%env(BAZ)%'));
$containerBuilder->setAlias('%alias.id%', 'foo');

View File

@ -29,6 +29,7 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container
$this->services = array();
$this->methodMap = array(
'bar' => 'getBarService',
'test' => 'getTestService',
);
@ -60,6 +61,16 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container
return true;
}
/**
* Gets the public 'bar' shared service.
*
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
*/
protected function getBarService()
{
return $this->services['bar'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\Bar($this->getEnv('QUZ'));
}
/**
* Gets the public 'test' shared service.
*

View File

@ -15,3 +15,8 @@ services:
- '%env(Bar)%'
- 'foo%bar%baz'
- '%baz%'
bar:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
public: true
bind:
$quz: '%env(QUZ)%'