Skip to content

Commit 06341a6

Browse files
Merge branch '5.4' into 6.0
* 5.4: [Messenger] Fix dealing with unexpected payload in Redis transport [Filesystem] Update some PHPDoc of the Path class [VarDumper] Fix dumping mysqli_driver instances Fix missing ReturnTypeWillChange attributes [Cache] Add missing log when saving namespace [HttpKernel] Reset services between requests performed by KernelBrowser [HttpKernel] Remove unused argument in ArgumentMetadataFactory [Stopwatch] Fix test expectation [SecurityBundle] fix autoconfiguring Monolog's ProcessorInterface KernelTestCase resets internal state on tearDown [Security/Http] Fix getting password-upgrader when user-loader is a closure [HttpKernel] Fix extracting controller name from closures [Intl] fix wrong offset timezone PHP 8.1 Fix type binding Remove duplicated test [Dotenv] Fix reading config for symfony/runtime when running dump command [Serializer] Remove unnecessary break [Runtime] Fix dotenv_overload with commands Make document type nodes ignorable Initialize Symfony\Component\Security\Core\Exception\AccountStatusException:: property
2 parents 6c789db + 9c92c00 commit 06341a6

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

ControllerMetadata/ArgumentMetadataFactory.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ public function createArgumentMetadata(string|object|array $controller): array
2727

2828
if (\is_array($controller)) {
2929
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
30+
$class = $reflection->class;
3031
} elseif (\is_object($controller) && !$controller instanceof \Closure) {
31-
$reflection = (new \ReflectionObject($controller))->getMethod('__invoke');
32+
$reflection = new \ReflectionMethod($controller, '__invoke');
33+
$class = $reflection->class;
3234
} else {
3335
$reflection = new \ReflectionFunction($controller);
36+
if ($class = str_contains($reflection->name, '{closure}') ? null : $reflection->getClosureScopeClass()) {
37+
$class = $class->name;
38+
}
3439
}
3540

3641
foreach ($reflection->getParameters() as $param) {
@@ -41,7 +46,7 @@ public function createArgumentMetadata(string|object|array $controller): array
4146
}
4247
}
4348

44-
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes);
49+
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $class), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes);
4550
}
4651

4752
return $arguments;
@@ -50,20 +55,19 @@ public function createArgumentMetadata(string|object|array $controller): array
5055
/**
5156
* Returns an associated type to the given parameter if available.
5257
*/
53-
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function): ?string
58+
private function getType(\ReflectionParameter $parameter, ?string $class): ?string
5459
{
5560
if (!$type = $parameter->getType()) {
5661
return null;
5762
}
5863
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
5964

60-
if ($function instanceof \ReflectionMethod) {
61-
$lcName = strtolower($name);
62-
switch ($lcName) {
65+
if (null !== $class) {
66+
switch (strtolower($name)) {
6367
case 'self':
64-
return $function->getDeclaringClass()->name;
68+
return $class;
6569
case 'parent':
66-
return ($parent = $function->getDeclaringClass()->getParentClass()) ? $parent->name : null;
70+
return get_parent_class($class) ?: null;
6771
}
6872
}
6973

DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ public function process(ContainerBuilder $container)
147147
$args[$p->name] = $bindingValue;
148148
}
149149

150+
continue;
151+
} elseif (!$type || !$autowire || '\\' !== $target[0]) {
150152
continue;
151153
} elseif (is_subclass_of($type, \UnitEnum::class)) {
152154
// do not attempt to register enum typed arguments if not already present in bindings
153155
continue;
154-
} elseif (!$type || !$autowire || '\\' !== $target[0]) {
155-
continue;
156156
} elseif (!$p->allowsNull()) {
157157
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
158158
}

Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ public function testBasicTypesSignature()
107107
], $arguments);
108108
}
109109

110+
public function testNamedClosure()
111+
{
112+
$arguments = $this->factory->createArgumentMetadata(\Closure::fromCallable([$this, 'signature1']));
113+
114+
$this->assertEquals([
115+
new ArgumentMetadata('foo', self::class, false, false, null),
116+
new ArgumentMetadata('bar', 'array', false, false, null),
117+
new ArgumentMetadata('baz', 'callable', false, false, null),
118+
], $arguments);
119+
}
120+
110121
public function testNullableTypesSignature()
111122
{
112123
$arguments = $this->factory->createArgumentMetadata([new NullableController(), 'action']);

0 commit comments

Comments
 (0)