Permalink
Browse files

bug #3707 make method supportsClass() in custom voter compatible with…

… the interface's documentation (xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

make method supportsClass() in custom voter compatible with the interface's documentation

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | all
| Fixed tickets | #3702

Commits
-------

36384db make method supportsClass() in custom voter compatible with the interface's documentation
  • Loading branch information...
weaverryan committed Mar 24, 2014
2 parents 5035837 + 36384db commit aadc61d4e42a09461120cc940ee1add2ae5b95e5
Showing with 5 additions and 4 deletions.
  1. +5 −4 cookbook/security/voters_data_permission.rst
@@ -64,7 +64,6 @@ edit a particular object. Here's an example implementation::
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Acme\DemoBundle\Entity\Post;
class PostVoter implements VoterInterface
{
@@ -79,9 +78,11 @@ edit a particular object. Here's an example implementation::
));
}
public function supportsClass($obj)
public function supportsClass($class)
{
return $obj instanceof Post;
$supportedClass = 'Acme\DemoBundle\Entity\Post';
return $supportedClass === $class || is_subclass_of($class, $supportedClass);
}
/**
@@ -90,7 +91,7 @@ edit a particular object. Here's an example implementation::
public function vote(TokenInterface $token, $post, array $attributes)
{
// check if class of this object is supported by this voter
if (!$this->supportsClass($post)) {
if (!$this->supportsClass(get_class($post))) {
return VoterInterface::ACCESS_ABSTAIN;
}

0 comments on commit aadc61d

Please sign in to comment.