src/AppBundle/Security/ActivityEntryVoter.php line 13

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Security;
  3. use AppBundle\Entity\ActivityEntry;
  4. use AppBundle\Entity\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. /**
  8.  * Class ActivityEntryVoter
  9.  */
  10. class ActivityEntryVoter extends Voter
  11. {
  12.     const EDIT 'edit';
  13.     /**
  14.      * {@inheritdoc}
  15.      */
  16.     protected function supports($attribute$subject)
  17.     {
  18.         return self::EDIT === $attribute && $subject instanceof ActivityEntry;
  19.     }
  20.     /**
  21.      * {@inheritdoc}
  22.      */
  23.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  24.     {
  25.         $user $token->getUser();
  26.         if (!$user instanceof User) {
  27.             return false;
  28.         }
  29.         /** @var ActivityEntry $subject */
  30.         return (!$subject->isInvoiced());
  31.     }
  32. }