Skip to content

Commit aadc61d

Browse files
committed
bug symfony#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 | symfony#3702 Commits ------- 36384db make method supportsClass() in custom voter compatible with the interface's documentation
2 parents 5035837 + 36384db commit aadc61d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cookbook/security/voters_data_permission.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ edit a particular object. Here's an example implementation::
6464
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
6565
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6666
use Symfony\Component\Security\Core\User\UserInterface;
67-
use Acme\DemoBundle\Entity\Post;
6867

6968
class PostVoter implements VoterInterface
7069
{
@@ -79,9 +78,11 @@ edit a particular object. Here's an example implementation::
7978
));
8079
}
8180

82-
public function supportsClass($obj)
81+
public function supportsClass($class)
8382
{
84-
return $obj instanceof Post;
83+
$supportedClass = 'Acme\DemoBundle\Entity\Post';
84+
85+
return $supportedClass === $class || is_subclass_of($class, $supportedClass);
8586
}
8687

8788
/**
@@ -90,7 +91,7 @@ edit a particular object. Here's an example implementation::
9091
public function vote(TokenInterface $token, $post, array $attributes)
9192
{
9293
// check if class of this object is supported by this voter
93-
if (!$this->supportsClass($post)) {
94+
if (!$this->supportsClass(get_class($post))) {
9495
return VoterInterface::ACCESS_ABSTAIN;
9596
}
9697

0 commit comments

Comments
 (0)