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 03cbbf5

Browse filesBrowse files
author
Douglas Greenshields
committed
[DependencyInjection] Handle ServiceClosureArgument for callable in container linting
1 parent 9d4c98e commit 03cbbf5
Copy full SHA for 03cbbf5

File tree

3 files changed

+34
-0
lines changed
Filter options

3 files changed

+34
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1516
use Symfony\Component\DependencyInjection\Container;
1617
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
@@ -219,6 +220,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
219220
return;
220221
}
221222

223+
if (in_array($type, ['callable', 'Closure']) && $value instanceof ServiceClosureArgument) {
224+
return;
225+
}
226+
222227
if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
223228
return;
224229
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
16+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1617
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
1718
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -697,4 +698,28 @@ public function testProcessHandleClosureForCallable()
697698

698699
$this->addToAssertionCount(1);
699700
}
701+
702+
public function testProcessSuccessWhenPassingServiceClosureArgumentToCallable()
703+
{
704+
$container = new ContainerBuilder();
705+
706+
$container->register('bar', BarMethodCall::class)
707+
->addMethodCall('setCallable', [new ServiceClosureArgument(new Reference('foo'))]);
708+
709+
(new CheckTypeDeclarationsPass(true))->process($container);
710+
711+
$this->addToAssertionCount(1);
712+
}
713+
714+
public function testProcessSuccessWhenPassingServiceClosureArgumentToClosure()
715+
{
716+
$container = new ContainerBuilder();
717+
718+
$container->register('bar', BarMethodCall::class)
719+
->addMethodCall('setClosure', [new ServiceClosureArgument(new Reference('foo'))]);
720+
721+
(new CheckTypeDeclarationsPass(true))->process($container);
722+
723+
$this->addToAssertionCount(1);
724+
}
700725
}

‎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
@@ -40,4 +40,8 @@ public function setIterable(iterable $iterable)
4040
public function setCallable(callable $callable): void
4141
{
4242
}
43+
44+
public function setClosure(\Closure $closure): void
45+
{
46+
}
4347
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.