File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,41 @@ role::
157157
158158 $roleHierarchyVoter = new RoleHierarchyVoter($roleHierarchy);
159159
160+ ExpressionVoter
161+ ~~~~~~~~~~~~~~~
162+
163+ The :class: `Symfony\\ Component\\ Security\\ Core\\ Authorization\\ Voter\\ ExpressionVoter `
164+ grants access based on the evaluation of expressions created with the
165+ :doc: `ExpressionLanguage component </components/expression_language >`. These
166+ expressions have access to a number of
167+ :ref: `special security variables <security-expression-variables >`::
168+
169+ use Symfony\Component\ExpressionLanguage\Expression;
170+ use Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter;
171+
172+ // Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
173+ $expressionLanguage = ...;
174+
175+ // instance of Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface
176+ $trustResolver = ...;
177+
178+ // Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
179+ $authorizationChecker = ...;
180+
181+ $expressionVoter = new ExpressionVoter($expressionLanguage, $trustResolver, $authorizationChecker);
182+
183+ // instance of Symfony\Component\Security\Core\Authentication\Token\TokenInterface
184+ $token = ...;
185+
186+ // any object
187+ $object = ...;
188+
189+ $expression = new Expression(
190+ '"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
191+ )
192+
193+ $vote = $expressionVoter->vote($token, $object, [$expression]);
194+
160195.. note ::
161196
162197 When you make your own voter, you can use its constructor to inject any
You can’t perform that action at this time.
0 commit comments