Skip to content

Commit aac9ca2

Browse files
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 | #35066 | License | MIT | Doc PR | - Commits ------- d6a7fbf [DependencyInjection][CheckTypeDeclarationsPass] Handle \Closure for callable
2 parents 0bd742a + d6a7fbf commit aac9ca2

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 = 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)
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