<?php
namespace AppBundle\Security;
use AppBundle\Entity\ActivityEntry;
use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* Class ActivityEntryVoter
*/
class ActivityEntryVoter extends Voter
{
const EDIT = 'edit';
/**
* {@inheritdoc}
*/
protected function supports($attribute, $subject)
{
return self::EDIT === $attribute && $subject instanceof ActivityEntry;
}
/**
* {@inheritdoc}
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
/** @var ActivityEntry $subject */
return (!$subject->isInvoiced());
}
}