Skip to content

[Documentation][Voter] updated documentation for CacheableVoterInterface #19531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions security/voters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,28 @@ The Voter Interface
-------------------

A custom voter needs to implement
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface`
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface`,
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\CacheableVoterInterface`
Comment on lines +38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface`,
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\CacheableVoterInterface`
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface` or
:class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\CacheableVoterInterface`

I'm not sure about why Voter implements both interfaces explicitly but since CacheableVoterInterface extends VoterInterface perhaps the documentation can mention that only one is needed ?

or extend :class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\Voter`,
which makes creating a voter even easier::

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

abstract class Voter implements VoterInterface
abstract class Voter implements VoterInterface, CacheableVoterInterface
{
abstract protected function supports(string $attribute, $subject) bool;
abstract protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool;

public function supportsAttribute(string $attribute): bool
{
return true;
}

public function supportsType(string $subjectType): bool
{
return true;
}
}

.. _how-to-use-the-voter-in-a-controller:
Expand Down