8000 [DependencyInjection][CheckTypeDeclarationsPass] Handle \Closure for … · symfony/symfony@d6a7fbf · GitHub
[go: up one dir, main page]

Skip to content

Commit d6a7fbf

Browse files
committed
[DependencyInjection][CheckTypeDeclarationsPass] Handle \Closure for callable
1 parent 5973dac commit d6a7fbf

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
166166
return;
167167
}
168168

169-
if ('callable' === $type && method_exists($class, '__invoke')) {
169+
if ('callable' === $type && (\Closure::class === $class || method_exists($class, '__invoke'))) {
170170
return;
171171
}
172172

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,20 @@ public function testProcessSkipSkippedIds()
681681

682682
$this->addToAssertionCount(1);
683683
}
684+
685+
public function testProcessHandleClosureForCallable()
686+
{
687+
$closureDefinition = new Definition(\Closure::class);
688+
$closureDefinition->setFactory([\Closure::class, 'fromCallable']);
689+
$closureDefinition->setArguments(['strlen']);
690+
691+
$container 8000 = new ContainerBuilder();
692+
$container
693+
->register('foobar', BarMethodCall::class)
694+
->addMethodCall('setCallable', [$closureDefinition]);
695+
696+
(new CheckTypeDeclarationsPass(true))->process($container);
697+
698+
$this->addToAssertionCount(1);
699+
}
684700
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ public function setArray(array $array)
3636
public function setIterable(iterable $iterable)
3737
{
3838
}
39+
40+
public function setCallable(callable $callable): void
41+
{
42+
}
3943
}

0 commit comments

Comments
 (0)
0