Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitaadc61d

Browse files
committed
bugsymfony#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#3702Commits-------36384db make method supportsClass() in custom voter compatible with the interface's documentation
2 parents5035837 +36384db commitaadc61d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎cookbook/security/voters_data_permission.rst

Lines 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)

[8]ページ先頭

©2009-2025 Movatter.jp