Skip to content

Commit 3b240ed

Browse files
Merge branch '4.4' into 5.0
* 4.4: [Debug] fix ClassNotFoundFatalErrorHandler [Routing] Fix using a custom matcher & generator dumper class [Serializer] Fix cache in MetadataAwareNameConverter [Dotenv] Fixed infinite loop with missing quote followed by quoted value [HttpClient] Added missing sprintf [TwigBridge] button_widget now has its title attr translated even if its label = null or false [PhpUnitBridge] When using phpenv + phpenv-composer plugin, composer executable is wrapped into a bash script [Messenger] Added check if json_encode succeeded [Messenger] Added check if json_encode succeeded [FrameworkBundle][ContainerLintCommand] Only skip .errored. services [HttpClient] fix exception in case of PSR17 discovery failure [DependencyInjection] Handle ServiceClosureArgument for callable in container linting fix processing chain adapter based cache pool [HttpKernel] release lock explicitly [Security] Prevent canceled remember-me cookie from being accepted [FrameworkBundle][TranslationUpdateCommand] Do not output positive feedback on stderr [Security\Guard] Fix missing typehints do not render preferred choices as selected
2 parents 5292e03 + 1f2b771 commit 3b240ed

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Compiler/CheckTypeDeclarationsPass.php

Lines 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'], true) && $value instanceof ServiceClosureArgument) {
224+
return;
225+
}
226+
222227
if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
223228
return;
224229
}

Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines 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
}

Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php

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