Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d6a7fbf

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

File tree

3 files changed

+21
-1
lines changed
Filter options

3 files changed

+21
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php
+16Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php
+4Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.