src/Security/Voter/CloneVoter.php line 10
<?php
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authorization\Voter\Voter,
Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use App\Lib\Actions,
App\Repository\RegistryEntryRepository;
final class CloneVoter extends Voter
{
const SINCE = '10 secs';
const MESSAGE = 'Clone operation can be performed once a ' . self::SINCE . '.';
private RegistryEntryRepository $repository;
public function __construct(RegistryEntryRepository $repository)
{
$this->repository = $repository;
}
protected function supports($attribute, $subject): bool
{
if (Actions::CLONE !== $attribute) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$operations = $this->repository->findAllCloneOperations(
admin: $token->getUser(),
since: new \DateTimeImmutable('-' . self::SINCE)
);
if (count($operations)) {
return false;
}
return true;
}
}