<?php
declare(strict_types=1);
namespace App\Point\Security\Voter;
use App\Point\Doctrine\Entity\Transfer;
use App\Program\Doctrine\Entity\Profile;
use App\Program\Doctrine\Entity\Program;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
final class TransferVoter extends Voter
{
protected function supports(string $attribute, mixed $subject): bool
{
return $subject instanceof Transfer && 'item' === $attribute;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
/** @var Transfer $transfer */
$transfer = $subject;
/** @var Program $program */
$program = $token->getUser();
/** @var Profile $profile */
$profile = $transfer->getFrom()->getProfile();
return $profile->getProgram() === $program;
}
}