src/Security/BlogVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use App\Model\User\User;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. class BlogVoter extends Voter
  7. {
  8.     public const GET_BLOG 'get_blog';
  9.     public const ARRAY_BLOG_VOTER = [
  10.         self::GET_BLOG,
  11.     ];
  12.     protected function supports($attribute$subject): bool
  13.     {
  14.         return in_array($attributeself::ARRAY_BLOG_VOTER);
  15.     }
  16.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  17.     {
  18.         if (true == $subject) {
  19.             return true;
  20.         }
  21.         $user $token->getUser();
  22.         if (!$user instanceof User) {
  23.             return false;
  24.         }
  25.         return true;
  26.     }
  27. }