src/Security/Voter/Resource/ProfileVoter.php line 9

  1. <?php
  2. namespace App\Security\Voter\Resource;
  3. use Symfony\Component\Security\Core\Authorization\Voter\Voter,
  4.     Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use App\Entity\Admin;
  6. final class ProfileVoter extends Voter
  7. {
  8.     const ATTRIBUTE 'PROFILE';
  9.     protected function supports($attribute$subject): bool
  10.     {
  11.         if (! $subject instanceof Admin || $attribute !== self::ATTRIBUTE) {
  12.             return false;
  13.         }
  14.         return true;
  15.     }
  16.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  17.     {
  18.         /** @var Admin */
  19.         $admin $token->getUser();
  20.         if ($admin->getUuid() === $subject->getUuid()) {
  21.             return true;
  22.         }
  23.         return false;
  24.     }
  25. }