Skip to content

Commit

Permalink
bug #35067 [DependencyInjection][CheckTypeDeclarationsPass] Handle \C…
Browse files Browse the repository at this point in the history
…losure 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
  • Loading branch information
nicolas-grekas committed Dec 26, 2019
2 parents 0bd742a + d6a7fbf commit aac9ca2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Expand Up @@ -166,7 +166,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
return;
}

if ('callable' === $type && method_exists($class, '__invoke')) {
if ('callable' === $type && (\Closure::class === $class || method_exists($class, '__invoke'))) {
return;
}

Expand Down
Expand Up @@ -681,4 +681,20 @@ public function testProcessSkipSkippedIds()

$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);
}
}
Expand Up @@ -36,4 +36,8 @@ public function setArray(array $array)
public function setIterable(iterable $iterable)
{
}

public function setCallable(callable $callable): void
{
}
}

0 comments on commit aac9ca2

Please sign in to comment.