<?php
namespace App\Security;
namespace App\Security;
use App\Entity\Team;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class TeamVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
if ($attribute === 'VIEW_TEAMS') {
return true;
}
return $subject instanceof Team && $attribute === 'VIEW';
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user) {
return false;
}
if ($attribute === 'VIEW_TEAMS') {
return true;
}
if ($subject instanceof Team) {
return true;
}
return false;
}
}