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