Fix container lint command when a synthetic service is used in combination with the expression language

This commit is contained in:
HypeMC 2020-02-29 18:13:08 +01:00 committed by Nicolas Grekas
parent 2bd76fa32c
commit e7fa73a32b
2 changed files with 22 additions and 1 deletions

View File

@ -191,7 +191,12 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
} 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.

View File

@ -739,4 +739,20 @@ class CheckTypeDeclarationsPassTest extends TestCase
$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);
}
}