File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,40 @@ role::
159
159
160
160
$roleHierarchyVoter = new RoleHierarchyVoter($roleHierarchy);
161
161
162
+ ExpressionVoter
163
+ ~~~~~~~~~~~~~~~~~~
164
+ The :class: `Symfony\\ Component\\ Security\\ Core\\ Authorization\\ Voter\\ ExpressionVoter `
165
+ supports :class: `Symfony\\ Component\\ ExpressionLanguage\\ Expression ` attributes
166
+ and grants access based on the evaluation of expression (See :doc: `/security/expressions ` )
167
+
168
+ .. code-block :: php
169
+
170
+ use Symfony\Component\ExpressionLanguage\Expression;
171
+ use Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter;
172
+
173
+ // Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
174
+ $expressionLanguage = ...;
175
+
176
+ // instance of Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface
177
+ $trustResolver = ...;
178
+
179
+ // Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
180
+ $authorizationChecker = ...;
181
+
182
+ $expressionVoter = new ExpressionVoter($expressionLanguage, $trustResolver, $authorizationChecker);
183
+
184
+ // instance of Symfony\Component\Security\Core\Authentication\Token\TokenInterface
185
+ $token = ...;
186
+
187
+ // any object
188
+ $object = ...;
189
+
190
+ $expression = new Expression(
191
+ '"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
192
+ )
193
+
194
+ $vote = $expressionVoter->vote($token, $object, array($expression));
195
+
162
196
.. note ::
163
197
164
198
When you make your own voter, you may of course use its constructor
You can’t perform that action at this time.
0 commit comments