Skip to content

Commit

Permalink
bug #35949 [DI] Fix container lint command when a synthetic service i…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
nicolas-grekas committed Mar 12, 2020
2 parents 26b123d + e7fa73a commit 2bf9991
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -191,7 +191,12 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
} elseif ($value instanceof Parameter) {
$value = $this->container->getParameter($value);
} elseif ($value instanceof Expression) {
$value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this->container]);
try {
$value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this->container]);
} catch (\Exception $e) {
// If a service from the expression cannot be fetched from the container, we skip the validation.
return;
}
} elseif (\is_string($value)) {
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
// Only array parameters are not inlined when dumped.
Expand Down
Expand Up @@ -739,4 +739,20 @@ public function testProcessSuccessWhenPassingServiceClosureArgumentToClosure()

$this->addToAssertionCount(1);
}

public function testExpressionLanguageWithSyntheticService()
{
$container = new ContainerBuilder();

$container->register('synthetic')
->setSynthetic(true);
$container->register('baz', \stdClass::class)
->addArgument(new Reference('synthetic'));
$container->register('bar', Bar::class)
->addArgument(new Expression('service("baz").getStdClass()'));

(new CheckTypeDeclarationsPass())->process($container);

$this->addToAssertionCount(1);
}
}

0 comments on commit 2bf9991

Please sign in to comment.