Skip to content

Commit da4e85e

Browse files
committed
bug symfony#12030 Fix expression language in the container when using the "container" variable (fabpot)
This PR was squashed before being merged into the 2.4 branch (closes symfony#12030). Discussion ---------- Fix expression language in the container when using the "container" variable | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#11995 | License | MIT | Doc PR | n/a See symfony#11995 for the description of the problem. Commits ------- 2b2f0df Fix expression language in the container when using the "container" variable
2 parents efb1237 + 2b2f0df commit da4e85e

File tree

12 files changed

+33
-11
lines changed

12 files changed

+33
-11
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ private function dumpValue($value, $interpolate = true)
12121212

12131213
return $this->getServiceCall((string) $value, $value);
12141214
} elseif ($value instanceof Expression) {
1215-
return $this->getExpressionLanguage()->compile((string) $value, array('container'));
1215+
return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container'));
12161216
} elseif ($value instanceof Parameter) {
12171217
return $this->dumpParameter($value);
12181218
} elseif (true === $interpolate && is_string($value)) {

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
addMethodCall('setBar', array(new Reference('foo2', ContainerInterface::NULL_ON_INVALID_REFERENCE)))->
5353
addMethodCall('setBar', array(new Reference('foo3', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))->
5454
addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))->
55-
addMethodCall('setBar', array(new Expression('service("foo").foo() ~ parameter("foo")')))
55+
addMethodCall('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")')))
5656
;
5757
$container->
5858
register('factory_service', 'Bar')->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function getMethodCall1Service()
197197
if ($this->has('foobaz')) {
198198
$instance->setBar($this->get('foobaz', ContainerInterface::NULL_ON_INVALID_REFERENCE));
199199
}
200-
$instance->setBar(($this->get("foo")->foo() . $this->getParameter("foo")));
200+
$instance->setBar(($this->get("foo")->foo() . (($this->hasparameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
201201

202202
return $instance;
203203
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected function getMethodCall1Service()
202202

203203
$instance->setBar($this->get('foo'));
204204
$instance->setBar(NULL);
205-
$instance->setBar(($this->get("foo")->foo() . $this->getParameter("foo")));
205+
$instance->setBar(($this->get("foo")->foo() . (($this->hasparameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
206206

207207
return $instance;
208208
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<service id="method_call1" class="FooClass">
3434
<call method="setBar" />
3535
<call method="setBar">
36-
<argument type="expression">service("foo").foo() ~ parameter("foo")</argument>
36+
<argument type="expression">service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")</argument>
3737
</call>
3838
</service>
3939
<service id="method_call2" class="FooClass">

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<argument type="service" id="foobaz" on-invalid="ignore"/>
5555
</call>
5656
<call method="setBar">
57-
<argument type="expression">service("foo").foo() ~ parameter("foo")</argument>
57+
<argument type="expression">service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")</argument>
5858
</call>
5959
</service>
6060
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
calls:
1616
- [ setBar, [] ]
1717
- [ setBar ]
18-
- [ setBar, ['@=service("foo").foo() ~ parameter("foo")'] ]
18+
- [ setBar, ['@=service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")'] ]
1919
method_call2:
2020
class: FooClass
2121
calls:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ services:
3838
- [setBar, ['@?foo2']]
3939
- [setBar, ['@?foo3']]
4040
- [setBar, ['@?foobaz']]
41-
- [setBar, ['@=service("foo").foo() ~ parameter("foo")']]
41+
- [setBar, ['@=service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")']]
4242

4343
factory_service:
4444
class: Bar

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function testLoadServices()
210210
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
211211
$this->assertEquals(array(new Reference('baz', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
212212
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
213-
$this->assertEquals(array(array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ parameter("foo")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
213+
$this->assertEquals(array(array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
214214
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
215215
$this->assertNull($services['factory_service']->getClass());
216216
$this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod());

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testLoadServices()
138138
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
139139
$this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
140140
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
141-
$this->assertEquals(array(array('setBar', array()), array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ parameter("foo")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
141+
$this->assertEquals(array(array('setBar', array()), array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
142142
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
143143
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
144144

0 commit comments

Comments
 (0)