src/Security/Voter/Calendar/Pain/Preview/PdfPreviewVoter.php line 12

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security\Voter\Calendar\Pain\Preview;
  4. use App\Data\User\PatientUser;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class PdfPreviewVoter extends Voter
  8. {
  9.     protected function supports(string $attributemixed $subject): bool
  10.     {
  11.         return $subject instanceof PatientUser && $attribute === 'PAIN_CALENDAR_PDF_PREVIEW';
  12.     }
  13.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  14.     {
  15.         $user $token->getUser();
  16.         if ($user instanceof PatientUser && $subject instanceof PatientUser) {
  17.             return $user === $subject;
  18.         }
  19.         return false;
  20.     }
  21. }