@@ -91,16 +91,15 @@ retrieved from the token storage::
9191 use Symfony\Component\HttpFoundation\Request;
9292 use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
9393 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;
9695
9796 class UserValueResolver implements ArgumentValueResolverInterface
9897 {
99- private $tokenStorage ;
98+ private $security ;
10099
101- public function __construct(TokenStorageInterface $tokenStorage )
100+ public function __construct(Security $security )
102101 {
103- $this->tokenStorage = $tokenStorage ;
102+ $this->security = $security ;
104103 }
105104
106105 public function supports(Request $request, ArgumentMetadata $argument)
@@ -109,27 +108,20 @@ retrieved from the token storage::
109108 return false;
110109 }
111110
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;
119112 }
120113
121114 public function resolve(Request $request, ArgumentMetadata $argument)
122115 {
123- yield $this->tokenStorage->getToken() ->getUser();
116+ yield $this->security ->getUser();
124117 }
125118 }
126119
127120In order to get the actual ``User `` object in your argument, the given value
128121must fulfill the following requirements:
129122
130123* 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.
133125
134126When all those requirements are met and ``true `` is returned, the
135127``ArgumentResolver `` calls ``resolve() `` with the same values as it called
0 commit comments