Fix container lint command when a synthetic service is used in combination with the expression language
This commit is contained in:
parent
2bd76fa32c
commit
e7fa73a32b
|
@ -191,7 +191,12 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
||||||
} elseif ($value instanceof Parameter) {
|
} elseif ($value instanceof Parameter) {
|
||||||
$value = $this->container->getParameter($value);
|
$value = $this->container->getParameter($value);
|
||||||
} elseif ($value instanceof Expression) {
|
} 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)) {
|
} elseif (\is_string($value)) {
|
||||||
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
|
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
|
||||||
// Only array parameters are not inlined when dumped.
|
// Only array parameters are not inlined when dumped.
|
||||||
|
|
|
@ -739,4 +739,20 @@ class CheckTypeDeclarationsPassTest extends TestCase
|
||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue