src/Security/Authorization/Voter/MassQueryVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Security\Authorization\Voter;
  3.  
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  6.  
  7. class MassQueryVoter implements VoterInterface
  8. {
  9.     const GENERATE 'GENERATE';
  10.     const LIST = 'LIST';
  11.  
  12.     public function supportsAttribute($attribute)
  13.     {
  14.  
  15.         return in_array($attribute, array(
  16.             self::GENERATE,
  17.             self::LIST,
  18.         ));
  19.     }
  20.  
  21.     public function supportsClass($class)
  22.     {
  23.  
  24.         $supportedClass 'MassQuery';
  25.  
  26.         if (is_string($class)) {
  27.             if ($class === $supportedClass) {
  28.                 return true;
  29.             } else {
  30.                 return false;
  31.             }
  32.         }
  33.         if(is_null($class)) {
  34.             return true;
  35.         }
  36.         return $supportedClass === get_class($class) || is_subclass_of(get_class($class), $supportedClass);
  37.     }
  38.  
  39.  
  40.     public function vote(TokenInterface $token$entity, array $attributes)
  41.     {
  42.         $user $token->getUser();
  43.         if (!is_object($user)) {
  44.             return VoterInterface::ACCESS_DENIED;
  45.         }
  46.  
  47.         if (!$this->supportsClass($entity)) {
  48.             return VoterInterface::ACCESS_ABSTAIN;
  49.         }
  50.         
  51.         $attribute $attributes[0];
  52.         if(is_array($attribute)) {
  53.             $attribute $attribute[0];
  54.         };
  55.         if($user->hasRole("SuperUsers") || $user->hasRole("Deliveries")) {
  56.             return VoterInterface::ACCESS_GRANTED;
  57.         }
  58.         return VoterInterface::ACCESS_DENIED;
  59.     }
  60. }