Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36384db

Browse filesBrowse files
committed
make method supportsClass() in custom voter compatible with the interface's documentation
1 parent 868de1e commit 36384db
Copy full SHA for 36384db

File tree

Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed

‎cookbook/security/voters_data_permission.rst

Copy file name to clipboardExpand all lines: cookbook/security/voters_data_permission.rst
+5-4Lines changed: 5 additions & 4 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.