diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 667c23c4dc600..aab5d6ec6683d 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1156,6 +1156,10 @@ private function addNewInstance(Definition $definition, string $return = '', str if (['Closure', 'fromCallable'] === $callable && [0] === array_keys($definition->getArguments())) { $callable = $definition->getArgument(0); + if ($callable instanceof ServiceClosureArgument) { + return $return.$this->dumpValue($callable).$tail; + } + $arguments = ['...']; if ($callable instanceof Reference || $callable instanceof Definition) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 5cf5c2c8b9889..eb8eaf34d25ed 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -1601,6 +1601,11 @@ public function testClosure() ->setFactory(['Closure', 'fromCallable']) ->setArguments([new Reference('bar')]); $container->register('bar', 'stdClass'); + $container->register('closure_of_service_closure', 'Closure') + ->setPublic('true') + ->setFactory(['Closure', 'fromCallable']) + ->setArguments([new ServiceClosureArgument(new Reference('bar2'))]); + $container->register('bar2', 'stdClass'); $container->compile(); $dumper = new PhpDumper($container); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/closure.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/closure.php index 41cae53e5dcc4..c231064711667 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/closure.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/closure.php @@ -23,6 +23,7 @@ public function __construct() $this->services = $this->privates = []; $this->methodMap = [ 'closure' => 'getClosureService', + 'closure_of_service_closure' => 'getClosureOfServiceClosureService', ]; $this->aliases = []; @@ -42,6 +43,7 @@ public function getRemovedIds(): array { return [ 'bar' => true, + 'bar2' => true, ]; } @@ -54,4 +56,20 @@ protected static function getClosureService($container) { return $container->services['closure'] = (new \stdClass())->__invoke(...); } + + /** + * Gets the public 'closure_of_service_closure' shared service. + * + * @return \Closure + */ + protected static function getClosureOfServiceClosureService($container) + { + $containerRef = $container->ref; + + return $container->services['closure_of_service_closure'] = #[\Closure(name: 'bar2', class: 'stdClass')] static function () use ($containerRef) { + $container = $containerRef->get(); + + return ($container->privates['bar2'] ??= new \stdClass()); + }; + } }