Skip to content

Commit 011ebe0

Browse files
Merge branch '6.3' into 6.4
* 6.3: [DependencyInjection][HttpKernel] Fix using `#[AutowireCallable]` with controller arguments
2 parents b34b764 + 8a34076 commit 011ebe0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Attribute/AutowireCallable.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Attribute;
1313

14+
use Symfony\Component\DependencyInjection\Definition;
1415
use Symfony\Component\DependencyInjection\Exception\LogicException;
1516
use Symfony\Component\DependencyInjection\Reference;
1617

@@ -38,4 +39,12 @@ public function __construct(
3839

3940
parent::__construct($callable ?? [new Reference($service), $method ?? '__invoke'], lazy: $lazy);
4041
}
42+
43+
public function buildDefinition(mixed $value, ?string $type, \ReflectionParameter $parameter): Definition
44+
{
45+
return (new Definition($type = \is_string($this->lazy) ? $this->lazy : ($type ?: 'Closure')))
46+
->setFactory(['Closure', 'fromCallable'])
47+
->setArguments([\is_array($value) ? $value + [1 => '__invoke'] : $value])
48+
->setLazy($this->lazy || 'Closure' !== $type && 'callable' !== (string) $parameter->getType());
49+
}
4150
}

Compiler/AutowirePass.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
316316
}
317317

318318
if ($attribute instanceof AutowireCallable) {
319-
$value = (new Definition($type = \is_string($attribute->lazy) ? $attribute->lazy : ($type ?: 'Closure')))
320-
->setFactory(['Closure', 'fromCallable'])
321-
->setArguments([\is_array($value) ? $value + [1 => '__invoke'] : $value])
322-
->setLazy($attribute->lazy || 'Closure' !== $type && 'callable' !== (string) $parameter->getType());
319+
$value = $attribute->buildDefinition($value, $type, $parameter);
323320
} elseif ($lazy = $attribute->lazy) {
324321
$definition = (new Definition($type))
325322
->setFactory('current')

0 commit comments

Comments
 (0)