<?php
namespace App\Security\Voter\Api;
use App\Entity\ClientCoachFavori;
use App\Entity\Profile\Client;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class ClientCoachFavoriVoter extends Voter
{
public const EDIT = 'edit';
protected function supports(
string $attribute,
$subject
) {
return in_array($attribute, [self::EDIT])
&& $subject instanceof ClientCoachFavori;
}
protected function voteOnAttribute(
string $attribute,
$subject,
TokenInterface $token
) {
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
return match ($attribute) {
self::EDIT => $subject->getClient()->getUserIdentifier() === $user->getUserIdentifier(),
default => false,
};
}
}