Skip to content

Commit 03cbbf5

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

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 5 additions & 0 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;
@@ -219,6 +220,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
219220
return;
220221
}
221222

223+
if (in_array($type, ['callable', 'Closure']) && $value instanceof ServiceClosureArgument) {
224+
return;
225+
}
226+
222227
if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
223228
return;
224229
}

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

Lines changed: 25 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,28 @@ 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+
}
713+
714+
public function testProcessSuccessWhenPassingServiceClosureArgumentToClosure()
715+
{
716+
$container = new ContainerBuilder();
717+
718+
$container->register('bar', BarMethodCall::class)
719+
->addMethodCall('setClosure', [new ServiceClosureArgument(new Reference('foo'))]);
720+
721+
(new CheckTypeDeclarationsPass(true))->process($container);
722+
723+
$this->addToAssertionCount(1);
724+
}
700725
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ public function setIterable(iterable $iterable)
4040
public function setCallable(callable $callable): void
4141
{
4242
}
43+
44+
public function setClosure(\Closure $closure): void
45+
{
46+
}
4347
}

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