. */ declare(strict_types=1); namespace App\Security\Voter; use App\Entity\Parts\Part; use App\Entity\UserSystem\User; use App\Services\UserSystem\VoterHelper; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; /** * A Voter that votes on Part entities. * * See parts permissions for valid operations. */ final class PartVoter extends Voter { final public const READ = 'read'; public function __construct(private readonly VoterHelper $helper) { } protected function supports($attribute, $subject): bool { if (is_a($subject, Part::class, true)) { return $this->helper->isValidOperation('parts', $attribute); } //Allow class name as subject return false; } protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool { //Null concealing operator means, that no return $this->helper->isGranted($token, 'parts', $attribute); } public function supportsAttribute(string $attribute): bool { return $this->helper->isValidOperation('parts', $attribute); } public function supportsType(string $subjectType): bool { return $subjectType === 'string' || is_a($subjectType, Part::class, true); } }