diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SecurityHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SecurityHelper.php index 527809b68e..6521833d6c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SecurityHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SecurityHelper.php @@ -2,7 +2,6 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper; -use Symfony\Component\Security\Acl\Voter\FieldVote; use Symfony\Component\Templating\Helper\Helper; use Symfony\Component\Security\SecurityContext; @@ -39,16 +38,8 @@ class SecurityHelper extends Helper if (null === $this->context) { return false; } - - if ($field !== null) { - if (null === $object) { - throw new \InvalidArgumentException('$object cannot be null when field is not null.'); - } - - $object = new FieldVote($object, $field); - } - return $this->context->vote($role, $object); + return $this->context->vote($role, $object, $field); } /** diff --git a/src/Symfony/Bundle/TwigBundle/Extension/SecurityExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/SecurityExtension.php index 970ea59d48..7e1eb11136 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/SecurityExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/SecurityExtension.php @@ -32,16 +32,8 @@ class SecurityExtension extends \Twig_Extension if (null === $this->context) { return false; } - - if ($field !== null) { - if (null === $object) { - throw new \InvalidArgumentException('$object cannot be null when field is not null.'); - } - - $object = new FieldVote($object, $field); - } - return $this->context->vote($role, $object); + return $this->context->vote($role, $object, $field); } /** diff --git a/src/Symfony/Component/Security/SecurityContext.php b/src/Symfony/Component/Security/SecurityContext.php index ff0df086ad..8efc950ea1 100644 --- a/src/Symfony/Component/Security/SecurityContext.php +++ b/src/Symfony/Component/Security/SecurityContext.php @@ -4,6 +4,7 @@ namespace Symfony\Component\Security; use Symfony\Component\Security\Authentication\Token\TokenInterface; use Symfony\Component\Security\Authorization\AccessDecisionManager; +use Symfony\Component\Security\Acl\Voter\FieldVote; /* * This file is part of the Symfony package. @@ -45,12 +46,20 @@ class SecurityContext return null === $this->token ? null : $this->token->getUser(); } - public function vote($attributes, $object = null) + public function vote($attributes, $object = null, $field = null) { if (null === $this->token || null === $this->accessDecisionManager) { return false; } + if ($field !== null) { + if (null === $object) { + throw new \InvalidArgumentException('$object cannot be null when field is not null.'); + } + + $object = new FieldVote($object, $field); + } + return $this->accessDecisionManager->decide($this->token, (array) $attributes, $object); }