<?php
declare(strict_types=1);
namespace App\Security\Voter;
use App\Entity\Activity;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class ActivityReviewVoter extends Voter
{
public const CURATE = 'curate';
protected function supports($attribute, $subject): bool
{
if ($attribute !== self::CURATE) {
return false;
}
if (!$subject instanceof Activity) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $activity, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
/** @var Activity $activity */
return $activity->getCuratorUserId() === $user->getId();
}
}