@@ -91,16 +91,15 @@ retrieved from the token storage::
91
91
use Symfony\Component\HttpFoundation\Request;
92
92
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
93
93
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
94
- use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
95
- use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
94
+ use Symfony\Component\Security\Core\Security;
96
95
97
96
class UserValueResolver implements ArgumentValueResolverInterface
98
97
{
99
- private $tokenStorage ;
98
+ private $security ;
100
99
101
- public function __construct(TokenStorageInterface $tokenStorage )
100
+ public function __construct(Security $security )
102
101
{
103
- $this->tokenStorage = $tokenStorage ;
102
+ $this->security = $security ;
104
103
}
105
104
106
105
public function supports(Request $request, ArgumentMetadata $argument)
@@ -109,27 +108,20 @@ retrieved from the token storage::
109
108
return false;
110
109
}
111
110
112
- $token = $this->tokenStorage->getToken();
113
-
114
- if (!$token instanceof TokenInterface) {
115
- return false;
116
- }
117
-
118
- return $token->getUser() instanceof User;
111
+ return $this->security->getUser() instanceof User;
119
112
}
120
113
121
114
public function resolve(Request $request, ArgumentMetadata $argument)
122
115
{
123
- yield $this->tokenStorage->getToken() ->getUser();
116
+ yield $this->security ->getUser();
124
117
}
125
118
}
126
119
127
120
In order to get the actual ``User `` object in your argument, the given value
128
121
must fulfill the following requirements:
129
122
130
123
* An argument must be type-hinted as ``User `` in your action method signature;
131
- * A security token must be present;
132
- * The value must be an instance of the ``User ``.
124
+ * The value must be an instance of the ``User `` class.
133
125
134
126
When all those requirements are met and ``true `` is returned, the
135
127
``ArgumentResolver `` calls ``resolve() `` with the same values as it called
0 commit comments