src/Security/Voter/ArchivableVoter.php line 10

  1. <?php
  2. namespace App\Security\Voter;
  3. use Symfony\Component\Security\Core\Authorization\Voter\Voter,
  4.     Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use App\Entity\Interface\ArchivableInterface,
  6.     App\Lib\Actions;
  7. final class ArchivableVoter extends Voter
  8. {
  9.     const MESSAGE 'Cannot delete unarchived resource.';
  10.     protected function supports($attribute$subject): bool
  11.     {
  12.         if (! $subject instanceof ArchivableInterface || Actions::DELETE !== $attribute) {
  13.             return false;
  14.         }
  15.         return true;
  16.     }
  17.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  18.     {
  19.         if (! $subject->getIsArchived()) {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24. }