app/Plugin/CustomerGroup42/Security/Authorization/Voter/CategoryVoter.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of CustomerGroup
  4.  *
  5.  * Copyright(c) Akira Kurozumi <info@a-zumi.net>
  6.  *
  7.  * https://a-zumi.net
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\CustomerGroup42\Security\Authorization\Voter;
  13. use Eccube\Entity\Category;
  14. use Plugin\CustomerGroup42\Service\Gate\GateContext;
  15. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  16. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  17. class CategoryVoter extends Voter
  18. {
  19.     public const VIEW 'view';
  20.     /**
  21.      * @var GateContext
  22.      */
  23.     private GateContext $gateContext;
  24.     public function __construct(GateContext $gateContext)
  25.     {
  26.         $this->gateContext $gateContext;
  27.     }
  28.     /**
  29.      * @param string $attribute
  30.      * @param $subject
  31.      *
  32.      * @return bool
  33.      */
  34.     protected function supports(string $attribute$subject): bool
  35.     {
  36.         return $subject instanceof Category && \in_array($attribute, [self::VIEW], true);
  37.     }
  38.     /**
  39.      * @param string $attribute
  40.      * @param $subject
  41.      * @param TokenInterface $token
  42.      *
  43.      * @return bool
  44.      */
  45.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  46.     {
  47.         return $this->gateContext->permit($attribute$subject$token);
  48.     }
  49. }