Skip to content

Commit 23f534e

Browse files
Merge branch '6.4' into 7.0
* 6.4: [HttpKernel] fix test [Notifier] Document Amazon Notifier SSLMODE option [DependencyInjection][HttpKernel] Fix using `#[AutowireCallable]` with controller arguments
2 parents db924ba + 011ebe0 commit 23f534e

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
@@ -312,10 +312,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
312312
}
313313

314314
if ($attribute instanceof AutowireCallable) {
315-
$value = (new Definition($type = \is_string($attribute->lazy) ? $attribute->lazy : ($type ?: 'Closure')))
316-
->setFactory(['Closure', 'fromCallable'])
317-
->setArguments([\is_array($value) ? $value + [1 => '__invoke'] : $value])
318-
->setLazy($attribute->lazy || 'Closure' !== $type && 'callable' !== (string) $parameter->getType());
315+
$value = $attribute->buildDefinition($value, $type, $parameter);
319316
} elseif ($lazy = $attribute->lazy) {
320317
$definition = (new Definition($type))
321318
->setFactory('current')

0 commit comments

Comments
 (0)