8000 bug #41485 [HttpKernel] fix ArgumentMetadataFactory messes up control… · symfony/symfony@4500326 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4500326

Browse files
committed
bug #41485 [HttpKernel] fix ArgumentMetadataFactory messes up controller arguments with attributes (sgehrig)
This PR was merged into the 5.3 branch. Discussion ---------- [HttpKernel] fix ArgumentMetadataFactory messes up controller arguments with attributes | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes/no | New feature? | no | Deprecations? | no | Tickets | Fix #41478 | License | MIT | Doc PR | n/a fixes issue #41478 by resetting the $attributes array per controller argument also adds test to ensure correct metadata in cases where controller arguments without attributes follow arguments with attributes Commits ------- bda0360 fixes issue #41478 by resetting the $attributes array per controller argument
2 parents 45e1b1e + bda0360 commit 4500326

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function createArgumentMetadata($controller): array
3434
}
3535

3636
foreach ($reflection->getParameters() as $param) {
37+
$attributes = [];
3738
if (\PHP_VERSION_ID >= 80000) {
3839
foreach ($param->getAttributes() as $reflectionAttribute) {
3940
if (class_exists($reflectionAttribute->getName())) {
@@ -42,7 +43,7 @@ public function createArgumentMetadata($controller): array
4243
}
4344
}
4445

45-
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes ?? []);
46+
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes);
4647
}
4748

4849
return $arguments;

src/Symfony/Component/HttpKernel/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ public function testMultipleAttributes()
140140
$this->assertCount(1, $this->factory->createArgumentMetadata([new AttributeController(), 'multiAttributeArg'])[0]->getAttributes());
141141
}
142142

143+
/**
144+
* @requires PHP 8
145+
*/
146+
public function testIssue41478()
147+
{
148+
$arguments = $this->factory->createArgumentMetadata([new AttributeController(), 'issue41478']);
149+
$this->assertEquals([
150+
new ArgumentMetadata('baz', 'string', false, false, null, false, [new Foo('bar')]),
151+
new ArgumentMetadata('bat', 'string', false, false, null, false, []),
152+
], $arguments);
153+
}
154+
143155
private function signature1(self $foo, array $bar, callable $baz)
144156
{
145157
}

src/Symfony/Component/HttpKernel/Tests/Fixtures/Controller/AttributeController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ public function action(#[Foo('bar')] string $baz) {
2020

2121
public function multiAttributeArg(#[Foo('bar'), Undefined('bar')] string $baz) {
2222
}
23+
24+
public function issue41478(#[Foo('bar')] string $baz, string $bat) {
25+
}
2326
}

0 commit comments

Comments
 (0)
0