<?php
namespace App\V4\Voters;
use App\Security\User;
use LogicException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
class UserInfoVoter extends Voter
{
const USER_INFO_SHOW_LIST = 'user_info_show_list';
/**
* @var Security
*/
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* @param $attribute
* @param $subject
*
* @return bool
*/
protected function supports($attribute, $subject): bool
{
return in_array($attribute, [
self::USER_INFO_SHOW_LIST,
], true);
}
/**
* @param $attribute
* @param $subject
* @param TokenInterface $token
*
* @return bool
*
* @throws LogicException
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
switch ($attribute) {
case self::USER_INFO_SHOW_LIST:
return $this->canUserInfoShowList();
}
throw new LogicException('This should never happen');
}
/**
* @return bool
*/
private function canUserInfoShowList(): bool
{
return true;
}
}