<?php
namespace AppBundle\Security;
use AppBundle\Entity\User;
use CommonBundle\Model\UserConfinedInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* Class UserConfinedVoter
*/
class UserConfinedVoter extends Voter
{
/**
* {@inheritdoc}
*/
protected function supports($attribute, $subject)
{
return $subject instanceof UserConfinedInterface;
}
/**
* {@inheritdoc}
* @param UserConfinedInterface $subject
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return $user->getId() === $subject->getUserWithRights()->getId();
}
}