bug #35067 [DependencyInjection][CheckTypeDeclarationsPass] Handle \Closure for callable (fancyweb)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection][CheckTypeDeclarationsPass] Handle \Closure for callable

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | https://github.com/symfony/symfony/issues/35066
| License       | MIT
| Doc PR        | -

Commits
-------

d6a7fbfbc3 [DependencyInjection][CheckTypeDeclarationsPass] Handle \Closure for callable
This commit is contained in:
Nicolas Grekas 2019-12-26 09:58:10 +01:00
commit aac9ca2a88
3 changed files with 21 additions and 1 deletions

View File

@ -166,7 +166,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
return;
}
if ('callable' === $type && method_exists($class, '__invoke')) {
if ('callable' === $type && (\Closure::class === $class || method_exists($class, '__invoke'))) {
return;
}

View File

@ -681,4 +681,20 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->addToAssertionCount(1);
}
public function testProcessHandleClosureForCallable()
{
$closureDefinition = new Definition(\Closure::class);
$closureDefinition->setFactory([\Closure::class, 'fromCallable']);
$closureDefinition->setArguments(['strlen']);
$container = new ContainerBuilder();
$container
->register('foobar', BarMethodCall::class)
->addMethodCall('setCallable', [$closureDefinition]);
(new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1);
}
}

View File

@ -36,4 +36,8 @@ class BarMethodCall
public function setIterable(iterable $iterable)
{
}
public function setCallable(callable $callable): void
{
}
}