Skip to content

Commit 9f49d73

Browse files
author
Douglas Greenshields
committed
[DependencyInjection] Handle ServiceClosureArgument for callable in container linting
1 parent 9d4c98e commit 9f49d73

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1516
use Symfony\Component\DependencyInjection\Container;
1617
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
@@ -215,8 +216,13 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
215216
return;
216217
}
217218

218-
if ('callable' === $type && \is_array($value) && isset($value[0]) && ($value[0] instanceof Reference || $value[0] instanceof Definition)) {
219-
return;
219+
if ('callable' === $type) {
220+
if (\is_array($value) && isset($value[0]) && ($value[0] instanceof Reference || $value[0] instanceof Definition)) {
221+
return;
222+
}
223+
if ($value instanceof ServiceClosureArgument) {
224+
return;
225+
}
220226
}
221227

222228
if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
16+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1617
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
1718
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -697,4 +698,16 @@ public function testProcessHandleClosureForCallable()
697698

698699
$this->addToAssertionCount(1);
699700
}
701+
702+
public function testProcessSuccessWhenPassingServiceClosureArgumentToCallable()
703+
{
704+
$container = new ContainerBuilder();
705+
706+
$container->register('bar', BarMethodCall::class)
707+
->addMethodCall('setCallable', [new ServiceClosureArgument(new Reference('foo'))]);
708+
709+
(new CheckTypeDeclarationsPass(true))->process($container);
710+
711+
$this->addToAssertionCount(1);
712+
}
700713
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy