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

Commit0d12d93

Browse files
author
Robin Chalas
committed
[DI] Fix dumping expressions accessing single-use private services
1 parentf063587 commit0d12d93

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,8 @@ private function addServiceConfigurator(Definition $definition, string $variable
595595

596596
if (\is_array($callable)) {
597597
if ($callable[0]instanceof Reference
598-
|| ($callable[0]instanceof Definition &&$this->definitionVariables->contains($callable[0]))
599-
) {
600-
$callable[0] =$this->dumpValue($callable[0]);
601-
602-
returnsprintf(''.('$' ===$callable[0][0] ?'%s' :'(%s)')."->%s(\$%s);\n",$callable[0],$callable[1],$variableName);
598+
|| ($callable[0]instanceof Definition &&$this->definitionVariables->contains($callable[0]))) {
599+
returnsprintf(" %s->%s(\$%s);\n",$this->dumpValue($callable[0]),$callable[1],$variableName);
603600
}
604601

605602
$class =$this->dumpValue($callable[0]);
@@ -1629,7 +1626,7 @@ private function getServiceCall(string $id, Reference $reference = null): string
16291626
if (!$definition->isShared()) {
16301627
return$code;
16311628
}
1632-
}elseif ($this->isTrivialInstance($definition)) {
1629+
}elseif ($trivial =$this->isTrivialInstance($definition)) {
16331630
if ($e =$definition->getErrors()) {
16341631
$this->addThrow =true;
16351632

@@ -1650,6 +1647,8 @@ private function getServiceCall(string $id, Reference $reference = null): string
16501647
}
16511648
if ($definition->isShared() && !isset($this->singleUsePrivateIds[$id])) {
16521649
$code =sprintf('($this->%s[\'%s\'] ?? %s)',$definition->isPublic() ?'services' :'privates',$id,$code);
1650+
}elseif ($trivial ??false) {
1651+
$code ="($code)";
16531652
}
16541653

16551654
return$code;

‎src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public function testExpressionReferencingPrivateService()
799799
->setPublic(false);
800800
$container->register('public_foo','stdClass')
801801
->setPublic(true)
802-
->addArgument(newExpression('service("private_foo")'));
802+
->addArgument(newExpression('service("private_foo").bar'));
803803

804804
$container->compile();
805805
$dumper =newPhpDumper($container);

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public function getRemovedIds()
5656
*/
5757
protectedfunctiongetPublicFooService()
5858
{
59-
return$this->services['public_foo'] =new \stdClass(new \stdClass());
59+
return$this->services['public_foo'] =new \stdClass((new \stdClass())->bar);
6060
}
6161
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp