src/Security/Voter/InscriptionSessionFormationVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\InscriptionSessionFormation;
  4. use App\Entity\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class InscriptionSessionFormationVoter extends Voter
  8. {
  9.     public const DELETE 'INSCRIPTION_SESSION_DELETE';
  10.     protected function supports(string $attributemixed $subject): bool
  11.     {
  12.         return self::DELETE === $attribute && $subject instanceof InscriptionSessionFormation;
  13.     }
  14.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  15.     {
  16.         $user $token->getUser();
  17.         if (!$user instanceof User || !$subject instanceof InscriptionSessionFormation) {
  18.             return false;
  19.         }
  20.         $owner $subject->getUser();
  21.         return null !== $owner && $owner->getId() === $user->getId();
  22.     }
  23. }