src/Security/Voters/BackofficeVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voters;
  3. use App\Services\InstanceService;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. use Symfony\Component\Security\Core\Security;
  7. class BackofficeVoter extends Voter
  8. {
  9.   const VIEW 'view';
  10.   private $security;
  11.   /**
  12.    * @var InstanceService
  13.    */
  14.   private $is;
  15.   public function __construct(Security $securityInstanceService $instanceService)
  16.   {
  17.     $this->security $security;
  18.     $this->is $instanceService;
  19.   }
  20.   protected function supports($attribute$subject)
  21.   {
  22.     // if the attribute isn't one we support, return false
  23.     if (!in_array($attribute, [self::VIEW])) {
  24.       return false;
  25.     }
  26.     // only vote on `string` objects
  27.     if ($subject && !is_string($subject)) {
  28.       return false;
  29.     }
  30.     return true;
  31.   }
  32.   protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  33.   {
  34.     $backOfficePath $subject;
  35.     switch ($attribute) {
  36.       case self::VIEW:
  37.         return $this->canView($backOfficePath);
  38.     }
  39.     throw new \LogicException('This code should not be reached!');
  40.   }
  41.   private function canView(string $backOfficePath)
  42.   {
  43.     if (in_array($backOfficePath$this->is->getCurrentInstance()->getBackofficeEnabledIntegrations())) {
  44.       return true;
  45.     }
  46.     return false;
  47.   }
  48. }