summaryrefslogtreecommitdiffstats
path: root/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Core')
-rw-r--r--Core/Authorization/Voter/ExpressionVoter.php36
-rw-r--r--Core/Tests/Util/SecureRandomTest.php2
2 files changed, 24 insertions, 14 deletions
diff --git a/Core/Authorization/Voter/ExpressionVoter.php b/Core/Authorization/Voter/ExpressionVoter.php
index 50c8d5c..09953ac 100644
--- a/Core/Authorization/Voter/ExpressionVoter.php
+++ b/Core/Authorization/Voter/ExpressionVoter.php
@@ -62,6 +62,28 @@ class ExpressionVoter implements VoterInterface
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
+ $result = VoterInterface::ACCESS_ABSTAIN;
+ $variables = null;
+ foreach ($attributes as $attribute) {
+ if (!$this->supportsAttribute($attribute)) {
+ continue;
+ }
+
+ if (null === $variables) {
+ $variables = $this->getVariables($token, $object);
+ }
+
+ $result = VoterInterface::ACCESS_DENIED;
+ if ($this->expressionLanguage->evaluate($attribute, $variables)) {
+ return VoterInterface::ACCESS_GRANTED;
+ }
+ }
+
+ return $result;
+ }
+
+ private function getVariables(TokenInterface $token, $object)
+ {
if (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
} else {
@@ -83,18 +105,6 @@ class ExpressionVoter implements VoterInterface
$variables['request'] = $object;
}
- $result = VoterInterface::ACCESS_ABSTAIN;
- foreach ($attributes as $attribute) {
- if (!$this->supportsAttribute($attribute)) {
- continue;
- }
-
- $result = VoterInterface::ACCESS_DENIED;
- if ($this->expressionLanguage->evaluate($attribute, $variables)) {
- return VoterInterface::ACCESS_GRANTED;
- }
- }
-
- return $result;
+ return $variables;
}
}
diff --git a/Core/Tests/Util/SecureRandomTest.php b/Core/Tests/Util/SecureRandomTest.php
index 91d0489..4cfdb2c 100644
--- a/Core/Tests/Util/SecureRandomTest.php
+++ b/Core/Tests/Util/SecureRandomTest.php
@@ -68,7 +68,7 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
$runs[$i] = 0;
}
- $addRun = function($run) use (&$runs) {
+ $addRun = function ($run) use (&$runs) {
if ($run > 6) {
$run = 6;
}