<?php
namespace App\Security\Voter;
use App\Entity\Path;
use App\Utils\VoterHelper;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class PathVoter extends Voter
{
private const DELETE = 'delete';
private const CREATE = 'create';
/**
* PathVoter constructor.
*/
public function __construct()
{
}
protected function supports(string $attribute, mixed $subject): bool
{
return $subject instanceof Path && in_array($attribute, [self::DELETE, self::CREATE], true);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if (Path::TYPE_CURRENT == $subject->getType()) {
return false;
}
return VoterHelper::voteOnAttribute($attribute, $subject, $token, 'path');
}
}