src/Security/Voter/API/Appointment/PersonViewVoter.php line 12
<?phpnamespace App\Security\Voter\API\Appointment;use App\Entity\Appointment\AppointmentPerson;use App\Entity\User\PatientUser;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;use function is_array;use function is_iterable;class PersonViewVoter extends Voter{protected function supports(string $attribute, mixed $subject): bool{return $attribute === 'API_APPOINTMENT_PERSON_VIEW';}protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool{/** @var PatientUser $user */$user = $token->getUser();if (!$user instanceof PatientUser) {return false;}if (is_iterable($subject)) {foreach ($subject as $item) {if (!$item instanceof AppointmentPerson) {return false;}if (!$this->canView($item, $user)) {return false;}}return true;}else if ($subject instanceof AppointmentPerson) {return $this->canView($subject, $user);}return false;}private function canView(AppointmentPerson $person, PatientUser $user): bool{return $person->getAppointment()?->getPatient()?->getUser() === $user;}}