app/Plugin/CustomerGroup/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\CustomerGroup\Security\Authorization\Voter;
  13. use Eccube\Entity\Category;
  14. use Plugin\CustomerGroup\Utils\Accessible;
  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.     const VIEW 'view';
  20.     /**
  21.      * @var Accessible
  22.      */
  23.     private $accessible;
  24.     public function __construct(Accessible $accessible)
  25.     {
  26.         $this->accessible $accessible;
  27.     }
  28.     /**
  29.      * @param string $attribute
  30.      * @param mixed $subject
  31.      * @return bool
  32.      */
  33.     protected function supports($attribute$subject)
  34.     {
  35.         if (!in_array($attribute, [self::VIEW])) {
  36.             return false;
  37.         }
  38.         if (!$subject instanceof Category) {
  39.             return false;
  40.         }
  41.         return true;
  42.     }
  43.     /**
  44.      * @param string $attribute
  45.      * @param mixed $subject
  46.      * @param TokenInterface $token
  47.      * @return bool
  48.      */
  49.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  50.     {
  51.         if (self::VIEW === $attribute) {
  52.             return $this->accessible->can($attribute$subject$token);
  53.         }
  54.         throw new \LogicException();
  55.     }
  56. }