src/Security/Voters/ProductVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voters;
  3. use App\Entity\PriceMap;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. class ProductVoter extends Voter
  7. {
  8.     public const CAN_BE_DELETED  'product.can_be_deleted';
  9.     private const ATTRIBUTES = [
  10.         self::CAN_BE_DELETED,
  11.     ];
  12.     protected function supports($attribute$subject): bool
  13.     {
  14.         return in_array($attributeself::ATTRIBUTES);
  15.     }
  16.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  17.     {
  18.         $user $token->getUser();
  19.         switch ($attribute) {
  20.             case self::CAN_BE_DELETED:
  21.                 return $this->canBeDeleted($subject);
  22.         }
  23.         throw new \LogicException('Invalid attribute: '.$attribute);
  24.     }
  25.     private function canBeDeleted(PriceMap $product): bool
  26.     {
  27.         return true;
  28.     }
  29. }