[DependencyInjection] Handle ServiceClosureArgument for callable in container linting
This commit is contained in:
parent
9d4c98ee17
commit
e48829e9b6
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||||
|
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
|
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
|
||||||
@ -219,6 +220,10 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\in_array($type, ['callable', 'Closure'], true) && $value instanceof ServiceClosureArgument) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
|
if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||||
|
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
|
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
|
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
@ -697,4 +698,28 @@ class CheckTypeDeclarationsPassTest extends TestCase
|
|||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessSuccessWhenPassingServiceClosureArgumentToCallable()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$container->register('bar', BarMethodCall::class)
|
||||||
|
->addMethodCall('setCallable', [new ServiceClosureArgument(new Reference('foo'))]);
|
||||||
|
|
||||||
|
(new CheckTypeDeclarationsPass(true))->process($container);
|
||||||
|
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProcessSuccessWhenPassingServiceClosureArgumentToClosure()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$container->register('bar', BarMethodCall::class)
|
||||||
|
->addMethodCall('setClosure', [new ServiceClosureArgument(new Reference('foo'))]);
|
||||||
|
|
||||||
|
(new CheckTypeDeclarationsPass(true))->process($container);
|
||||||
|
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,8 @@ class BarMethodCall
|
|||||||
public function setCallable(callable $callable): void
|
public function setCallable(callable $callable): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setClosure(\Closure $closure): void
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user