Skip to content

Commit

Permalink
bug #3707 make method supportsClass() in custom voter compatible with…
Browse files Browse the repository at this point in the history
… 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 aadc61d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cookbook/security/voters_data_permission.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}

/**
Expand All @@ -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;
}

Expand Down

0 comments on commit aadc61d

Please sign in to comment.