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:
commit
aac9ca2a88
@ -166,7 +166,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('callable' === $type && method_exists($class, '__invoke')) {
|
if ('callable' === $type && (\Closure::class === $class || method_exists($class, '__invoke'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,4 +681,20 @@ class CheckTypeDeclarationsPassTest extends TestCase
|
|||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,8 @@ class BarMethodCall
|
|||||||
public function setIterable(iterable $iterable)
|
public function setIterable(iterable $iterable)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setCallable(callable $callable): void
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user