8000 bug #35949 [DI] Fix container lint command when a synthetic service i… · symfony/symfony@2bf9991 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2bf9991

Browse files
bug #35949 [DI] Fix container lint command when a synthetic service is used in an expression (HypeMC)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] Fix container lint command when a synthetic service is used in an expression Fix container lint command when a synthetic service is used in combination with the expression language. | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35691 | License | MIT | Doc PR | - Commits ------- e7fa73a Fix container lint command when a synthetic service is used in combination with the expression language
2 parents 26b123d + e7fa73a commit 2bf9991

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
191191
} elseif ($value instanceof Parameter) {
192192
$value = $this->container->getParameter($value);
193193
} elseif ($value instanceof Expression) {
194-
$value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this->container]);
194+
try {
195+
$value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this->container]);
196+
} catch (\Exception $e) {
197+
// If a service from the expression cannot be fetched from the container, we skip the validation.
198+
return;
199+
}
195200
} elseif (\is_string($value)) {
196201
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
197202
// Only array parameters are not inlined when dumped.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,20 @@ public function testProcessSuccessWhenPassingServiceClosureArgumentToClosure()
739739

740740
$this->addToAssertionCount(1);
741741
}
742+
743+
public function testExpressionLanguageWithSyntheticService()
744+
{
745+
$container = new ContainerBuilder();
746+
747+
$container->register('synthetic')
748+
->setSynthetic(true);
749+
$container->register('baz', \stdClass::class)
750+
->addArgument(new Reference('synthetic'));
751+
$container->register('bar', Bar::class)
752+
->addArgument(new Expression('service("baz").getStdClass()'));
753+
754+
(new CheckTypeDeclarationsPass())->process($container);
755+
756+
$this->addToAssertionCount(1);
757+
}
742758
}

0 commit comments

Comments
 (0)
0