<?php
namespace App\Security\Voter;
use App\Entity\PasswordReset;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class PasswordResetExpiredVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
return in_array($attribute, ['PASSWORD_RESET_NOT_EXPIRED'])
&& $subject instanceof PasswordReset;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
assert($attribute == 'PASSWORD_RESET_NOT_EXPIRED');
assert($subject instanceof PasswordReset);
return $subject->getExpiredAt() >= new \DateTimeImmutable();
}
}