src/Security/Voter/CvVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\Applicants;
  4. use App\Entity\Trait\ApplicantTrait;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class CvVoter extends Voter
  8. {
  9.     public const DELETE 'DELETE_CV_ITEM';
  10.     public const EDIT 'EDIT_CV_ITEM';
  11.     protected function supports(string $attribute$subject): bool
  12.     {
  13.         return in_array($attribute, [self::EDITself::DELETE]);
  14.     }
  15.     /**
  16.      * @param string $attribute
  17.      * @param $subject ApplicantTrait
  18.      * @param TokenInterface $token
  19.      * @return bool
  20.      */
  21.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  22.     {
  23.         $user $token->getUser();
  24.         if (!$user instanceof Applicants) {
  25.             return false;
  26.         }
  27.         if(!$subject->getApplicant() || $subject->getApplicant() === $user) {
  28.             return true;
  29.         }
  30.         return false;
  31.     }
  32. }