src/Security/Voter/Survey/Preview/PdfPreviewVoter.php line 13

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