@@ -61,6 +61,28 @@ public function supportsClass($class)
61
61
* {@inheritdoc}
62
62
*/
63
63
public function vote (TokenInterface $ token , $ object , array $ attributes )
64
+ {
65
+ $ result = VoterInterface::ACCESS_ABSTAIN ;
66
+ $ variables = null ;
67
+ foreach ($ attributes as $ attribute ) {
68
+ if (!$ this ->supportsAttribute ($ attribute )) {
69
+ continue ;
70
+ }
71
+
72
+ if (null === $ variables ) {
73
+ $ variables = $ this ->getVariables ($ token , $ object );
74
+ }
75
+
76
+ $ result = VoterInterface::ACCESS_DENIED ;
77
+ if ($ this ->expressionLanguage ->evaluate ($ attribute , $ variables )) {
78
+ return VoterInterface::ACCESS_GRANTED ;
79
+ }
80
+ }
81
+
82
+ return $ result ;
83
+ }
84
+
85
+ private function getVariables (TokenInterface $ token , $ object )
64
86
{
65
87
if (null !== $ this ->roleHierarchy ) {
66
88
$ roles = $ this ->roleHierarchy ->getReachableRoles ($ token ->getRoles ());
@@ -83,18 +105,6 @@ public function vote(TokenInterface $token, $object, array $attributes)
83
105
$ variables ['request ' ] = $ object ;
84
106
}
85
107
86
- $ result = VoterInterface::ACCESS_ABSTAIN ;
87
- foreach ($ attributes as $ attribute ) {
88
- if (!$ this ->supportsAttribute ($ attribute )) {
89
- continue ;
90
- }
91
-
92
- $ result = VoterInterface::ACCESS_DENIED ;
93
- if ($ this ->expressionLanguage ->evaluate ($ attribute , $ variables )) {
94
- return VoterInterface::ACCESS_GRANTED ;
95
- }
96
- }
97
-
98
- return $ result ;
108
+ return $ variables ;
99
109
}
100
110
}
0 commit comments