src/FMT/Application/Voter/CommandVoter.php line 13

Open in your IDE?
  1. <?php
  2. namespace FMT\Application\Voter;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. /**
  6.  * Class CommandVoter
  7.  * @package FMT\Application\Voter
  8.  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  9.  */
  10. class CommandVoter extends Voter
  11. {
  12.     const CAN_RUN_BY_REQUEST 'canRunByRequest';
  13.     protected static $allPermissions = [
  14.         self::CAN_RUN_BY_REQUEST,
  15.     ];
  16.     /** @var bool */
  17.     private $isProd;
  18.     /**
  19.      * CronVoter constructor.
  20.      * @param bool $isProd
  21.      */
  22.     public function __construct(bool $isProd)
  23.     {
  24.         $this->isProd $isProd;
  25.     }
  26.     /**
  27.      * @param string $attribute
  28.      * @param mixed $subject
  29.      * @return bool
  30.      */
  31.     protected function supports($attribute$subject)
  32.     {
  33.         if (!in_array($attributeself::$allPermissions)) {
  34.             return false;
  35.         }
  36.         return true;
  37.     }
  38.     /**
  39.      * @param string $attribute
  40.      * @param mixed $subject
  41.      * @param TokenInterface $token
  42.      * @return bool
  43.      */
  44.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  45.     {
  46.         if (method_exists($this$attribute)) {
  47.             return $this->$attribute();
  48.         }
  49.         return false;
  50.     }
  51.     /**
  52.      * @return bool
  53.      */
  54.     protected function canRunByRequest()
  55.     {
  56.         return !$this->isProd;
  57.     }
  58. }