<?php
/**
* This file is part of CustomerGroup
*
* Copyright(c) Akira Kurozumi <info@a-zumi.net>
*
* https://a-zumi.net
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\CustomerGroup\Security\Authorization\Voter;
use Eccube\Entity\Category;
use Plugin\CustomerGroup\Utils\Accessible;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class CategoryVoter extends Voter
{
const VIEW = 'view';
/**
* @var Accessible
*/
private $accessible;
public function __construct(Accessible $accessible)
{
$this->accessible = $accessible;
}
/**
* @param string $attribute
* @param mixed $subject
* @return bool
*/
protected function supports($attribute, $subject)
{
if (!in_array($attribute, [self::VIEW])) {
return false;
}
if (!$subject instanceof Category) {
return false;
}
return true;
}
/**
* @param string $attribute
* @param mixed $subject
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
if (self::VIEW === $attribute) {
return $this->accessible->can($attribute, $subject, $token);
}
throw new \LogicException();
}
}