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