From a79f8df76410bc741cb780608576ed7c0c34801b Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Sat, 10 Aug 2024 16:32:57 +0200 Subject: [PATCH] optimize sf voter --- Security/Voter/AclVoter.php | 10 ++++++++++ Security/Voter/SetPermissionVoter.php | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Security/Voter/AclVoter.php b/Security/Voter/AclVoter.php index 503f7e8..c9d644c 100644 --- a/Security/Voter/AclVoter.php +++ b/Security/Voter/AclVoter.php @@ -21,6 +21,16 @@ protected function supports(string $attribute, mixed $subject): bool return is_numeric($attribute) && $subject instanceof AclObjectInterface; } + public function supportsAttribute(string $attribute): bool + { + return is_numeric($attribute); + } + + public function supportsType(string $subjectType): bool + { + return is_a($subjectType, AclObjectInterface::class, true); + } + protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool { $user = $token->getUser(); diff --git a/Security/Voter/SetPermissionVoter.php b/Security/Voter/SetPermissionVoter.php index 3bfec99..9955fe1 100644 --- a/Security/Voter/SetPermissionVoter.php +++ b/Security/Voter/SetPermissionVoter.php @@ -25,10 +25,27 @@ protected function supports(string $attribute, mixed $subject): bool $attribute, [ self::ACL_READ, self::ACL_WRITE, - ] + ], + true ) && $subject instanceof AclObjectInterface; } + public function supportsAttribute(string $attribute): bool + { + return in_array( + $attribute, [ + self::ACL_READ, + self::ACL_WRITE, + ], + true + ); + } + + public function supportsType(string $subjectType): bool + { + return is_a($subjectType, AclObjectInterface::class, true); + } + /** * @param AclObjectInterface $subject */