src/Security/Voter/DayHoursChangeVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security\Voter;
  4. use App\Entity\{TimeNormalization\DayUser};
  5. use Symfony\Component\Security\Core\{Authentication\Token\TokenInterfaceAuthorization\Voter\VoterSecurity};
  6. /**
  7.  * Does user can change the hours in day?
  8.  */
  9. class DayHoursChangeVoter extends Voter
  10. {
  11.     private Security $security;
  12.     public function __construct(Security $security)
  13.     {
  14.         $this->security $security;
  15.     }
  16.     protected function supports(string $attribute$subject): bool
  17.     {
  18.         return $attribute === 'DAY_HOURS_EDIT' && $subject instanceof Day;
  19.     }
  20.     /**
  21.      * @param Day|mixed $subject
  22.      */
  23.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  24.     {
  25.         $user $token->getUser();
  26.         if (!$user instanceof User) {
  27.             return false;
  28.         }
  29.         return $this->security->isGranted('ROLE_ADMIN');
  30.     }
  31. }