src/Security/Voter/ActivityReviewVoter.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security\Voter;
  4. use App\Entity\Activity;
  5. use App\Entity\User;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class ActivityReviewVoter extends Voter
  9. {
  10.     public const CURATE 'curate';
  11.     protected function supports($attribute$subject): bool
  12.     {
  13.         if ($attribute !== self::CURATE) {
  14.             return false;
  15.         }
  16.         if (!$subject instanceof Activity) {
  17.             return false;
  18.         }
  19.         return true;
  20.     }
  21.     protected function voteOnAttribute($attribute$activityTokenInterface $token): bool
  22.     {
  23.         $user $token->getUser();
  24.         if (!$user instanceof User) {
  25.             return false;
  26.         }
  27.         /** @var Activity $activity */
  28.         return $activity->getCuratorUserId() === $user->getId();
  29.     }
  30. }