Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf11e2e9

Browse files
committed
bug#16295 [DependencyInjection] Unescape parameters for all types of injection (Nicofuma)
This PR was merged into the 2.3 branch.Discussion----------[DependencyInjection] Unescape parameters for all types of injection| Q | A| ------------- | ---| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |The parameters must be escaped when injected in the container.But they are only unescaped when the container is dumped and when these parameters are used in the service constructor.We need to unescape them every time their are injected (constructor, setter and property injection)Commits-------331a046 [DependencyInjection] Unescape parameters for all types of injection
2 parents1728dcc +331a046 commitf11e2e9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ public function createService(Definition $definition, $id, $tryProxy = true)
895895
$this->callMethod($service,$call);
896896
}
897897

898-
$properties =$this->resolveServices($parameterBag->resolveValue($definition->getProperties()));
898+
$properties =$this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getProperties())));
899899
foreach ($propertiesas$name =>$value) {
900900
$service->$name =$value;
901901
}
@@ -1054,7 +1054,7 @@ private function callMethod($service, $call)
10541054
}
10551055
}
10561056

1057-
call_user_func_array(array($service,$call[0]),$this->resolveServices($this->getParameterBag()->resolveValue($call[1])));
1057+
call_user_func_array(array($service,$call[0]),$this->resolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1]))));
10581058
}
10591059

10601060
/**

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,24 @@ public function testCreateServiceMethodCalls()
305305
$this->assertEquals(array('bar',$builder->get('bar')),$builder->get('foo1')->bar,'->createService() replaces the values in the method calls arguments');
306306
}
307307

308+
publicfunctiontestCreateServiceMethodCallsWithEscapedParam()
309+
{
310+
$builder =newContainerBuilder();
311+
$builder->register('bar','stdClass');
312+
$builder->register('foo1','FooClass')->addMethodCall('setBar',array(array('%%unescape_it%%')));
313+
$builder->setParameter('value','bar');
314+
$this->assertEquals(array('%unescape_it%'),$builder->get('foo1')->bar,'->createService() replaces the values in the method calls arguments');
315+
}
316+
317+
publicfunctiontestCreateServiceProperties()
318+
{
319+
$builder =newContainerBuilder();
320+
$builder->register('bar','stdClass');
321+
$builder->register('foo1','FooClass')->setProperty('bar',array('%value%',newReference('bar'),'%%unescape_it%%'));
322+
$builder->setParameter('value','bar');
323+
$this->assertEquals(array('bar',$builder->get('bar'),'%unescape_it%'),$builder->get('foo1')->bar,'->createService() replaces the values in the properties');
324+
}
325+
308326
publicfunctiontestCreateServiceConfigurator()
309327
{
310328
$builder =newContainerBuilder();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp