Skip to content

Commit be7540a

Browse files
committed
[HttpKernel] Handle multi-attribute controller arguments
1 parent 9196da3 commit be7540a

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

Attribute/CurrentUser.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
namespace Symfony\Component\Security\Http\Attribute;
1313

14-
use Symfony\Component\HttpKernel\Attribute\ArgumentInterface;
15-
1614
/**
1715
* Indicates that a controller argument should receive the current logged user.
1816
*/
1917
#[\Attribute(\Attribute::TARGET_PARAMETER)]
20-
class CurrentUser implements ArgumentInterface
18+
class CurrentUser
2119
{
2220
}

Controller/UserValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
3737
{
3838
// with the attribute, the type can be any UserInterface implementation
3939
// otherwise, the type must be UserInterface
40-
if (UserInterface::class !== $argument->getType() && !$argument->getAttribute() instanceof CurrentUser) {
40+
if (UserInterface::class !== $argument->getType() && !$argument->getAttributes(CurrentUser::class, ArgumentMetadata::IS_INSTANCEOF)) {
4141
return false;
4242
}
4343

Tests/Controller/UserValueResolverTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public function testResolveWithAttribute()
7777
$tokenStorage->setToken($token);
7878

7979
$resolver = new UserValueResolver($tokenStorage);
80-
$metadata = new ArgumentMetadata('foo', null, false, false, null, false, new CurrentUser());
80+
$metadata = $this->createMock(ArgumentMetadata::class);
81+
$metadata = new ArgumentMetadata('foo', null, false, false, null, false, [new CurrentUser()]);
8182

8283
$this->assertTrue($resolver->supports(Request::create('/'), $metadata));
8384
$this->assertSame([$user], iterator_to_array($resolver->resolve(Request::create('/'), $metadata)));
@@ -89,7 +90,7 @@ public function testResolveWithAttributeAndNoUser()
8990
$tokenStorage->setToken(new UsernamePasswordToken('username', 'password', 'provider'));
9091

9192
$resolver = new UserValueResolver($tokenStorage);
92-
$metadata = new ArgumentMetadata('foo', null, false, false, null, false, new CurrentUser());
93+
$metadata = new ArgumentMetadata('foo', null, false, false, null, false, [new CurrentUser()]);
9394

9495
$this->assertFalse($resolver->supports(Request::create('/'), $metadata));
9596
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.1",
2121
"symfony/security-core": "^5.3",
2222
"symfony/http-foundation": "^5.2",
23-
"symfony/http-kernel": "^5.2",
23+
"symfony/http-kernel": "^5.3",
2424
"symfony/polyfill-php80": "^1.15",
2525
"symfony/property-access": "^4.4|^5.0"
2626
},

0 commit comments

Comments
 (0)