<?php
namespace App\Security\Voter;
use App\Entity\InscriptionSessionFormation;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class InscriptionSessionFormationVoter extends Voter
{
public const DELETE = 'INSCRIPTION_SESSION_DELETE';
protected function supports(string $attribute, mixed $subject): bool
{
return self::DELETE === $attribute && $subject instanceof InscriptionSessionFormation;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User || !$subject instanceof InscriptionSessionFormation) {
return false;
}
$owner = $subject->getUser();
return null !== $owner && $owner->getId() === $user->getId();
}
}