<?php
namespace Bidcoz\Bundle\CoreBundle\Security\Authorization\Voter;
use Bidcoz\Bundle\CoreBundle\Entity\Auction\Item;
use RS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @DI\Service
* @DI\Tag("security.voter")
*/
class ItemVoter extends Voter
{
const VIEW = 'VIEW';
protected function supports($attribute, $subject)
{
return $subject instanceof Item && self::VIEW === $attribute;
}
protected function voteOnAttribute($attribute, $item, TokenInterface $token)
{
if (!$item->isPackagedItem()) {
return true;
}
// make sure there is a user object (i.e. that the user is logged in)
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
if ($user->hasRole('ROLE_SUPER_ADMIN')) {
return true;
}
return false;
}
}