*/ class BookingVoter extends Voter { public const VIEW = 'VIEW'; public const EDIT = 'EDIT'; protected function supports(string $attribute, mixed $subject): bool { if (false === in_array($attribute, [self::VIEW, self::EDIT])) { return false; } return $subject instanceof Booking; } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool { /** @var User|null $user */ $user = $token->getUser(); if (null === $user) { return false; } /** @var Booking $booking */ $booking = $subject; if ($booking->applicant->addressId !== $user->getAddressId()) { return false; } if (static::VIEW === $attribute) { return true; } return $booking->isEditable(); } }