Skip to content

Commit f278b8b

Browse files
committed
feature #43898 [Security] Make the abstract Voter class implement CacheableVoterInterface (javiereguiluz)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Security] Make the abstract Voter class implement CacheableVoterInterface | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Related to this --> https://symfony.com/blog/new-in-symfony-5-4-faster-security-voters The abstract `Voter` class is "a helper" to simplify the creation of custom voters. I propose to implement the new `CacheableVoterInterface`, so this nice feature is easier to discover and ready-to-use for those developers extending `Voter`. Commits ------- f230d0f002 [Security] Make the abstract Voter class implement CacheableVoterInterface
2 parents ea0d1dd + 6ef7002 commit f278b8b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Authorization/Voter/Voter.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author Roman Marintšenko <inoryy@gmail.com>
2020
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2121
*/
22-
abstract class Voter implements VoterInterface
22+
abstract class Voter implements VoterInterface, CacheableVoterInterface
2323
{
2424
/**
2525
* {@inheritdoc}
@@ -59,6 +59,26 @@ public function vote(TokenInterface $token, $subject, array $attributes)
5959
return $vote;
6060
}
6161

62+
/**
63+
* Return false if your voter doesn't support the given attribute. Symfony will cache
64+
* that decision and won't call your voter again for that attribute.
65+
*/
66+
public function supportsAttribute(string $attribute): bool
67+
{
68+
return true;
69+
}
70+
71+
/**
72+
* Return false if your voter doesn't support the given subject type. Symfony will cache
73+
* that decision and won't call your voter again for that subject type.
74+
*
75+
* @param string $subjectType The type of the subject inferred by `get_class()` or `get_debug_type()`
76+
*/
77+
public function supportsType(string $subjectType): bool
78+
{
79+
return true;
80+
}
81+
6282
/**
6383
* Determines if the attribute and subject are supported by this voter.
6484
*

0 commit comments

Comments
 (0)