src/Security/Authorization/Voter/MobileAppVoter.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 MobileAppVoter implements VoterInterface
  8. {
  9.     const LIST = 'LIST';
  10.  
  11.     public function supportsAttribute($attribute)
  12.     {
  13.  
  14.         return in_array($attribute, array(
  15.             self::LIST,
  16.         ));
  17.     }
  18.  
  19.     public function supportsClass($class)
  20.     {
  21.  
  22.         $supportedClass 'MobileApp';
  23.  
  24.         if (is_string($class)) {
  25.             if ($class === $supportedClass) {
  26.                 return true;
  27.             } else {
  28.                 return false;
  29.             }
  30.         }
  31.         if(is_null($class)) {
  32.             return true;
  33.         }
  34.         return $supportedClass === get_class($class) || is_subclass_of(get_class($class), $supportedClass);
  35.     }
  36.  
  37.  
  38.     public function vote(TokenInterface $token$entity, array $attributes)
  39.     {
  40.         $user $token->getUser();
  41.         if (!is_object($user)) {
  42.             return VoterInterface::ACCESS_DENIED;
  43.         }
  44.  
  45.         if (!$this->supportsClass($entity)) {
  46.             return VoterInterface::ACCESS_ABSTAIN;
  47.         }
  48.         
  49.         $attribute $attributes[0];
  50.         if(is_array($attribute)) {
  51.             $attribute $attribute[0];
  52.         };
  53.         if($user->hasRole("SuperUsers") || $user->hasRole("Deliveries")) {
  54.             return VoterInterface::ACCESS_GRANTED;
  55.         }
  56.         return VoterInterface::ACCESS_DENIED;
  57.     }
  58. }