src/Platform/Security/DashboardVoter.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Platform\Security;
  4. use App\Bundles\UserBundle\Entity\User;
  5. use LogicException;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class DashboardVoter extends Voter
  9. {
  10.     public const ENTITY_TYPE_VIEW   'entity_type_view';
  11.     protected function supports(string $attribute$subject): bool
  12.     {
  13.         // if the attribute isn't one we support, return false
  14.         if (!in_array($attribute, [self::ENTITY_TYPE_VIEW])) {
  15.             return false;
  16.         }
  17. //        // only vote on `SavedSearch` objects
  18. //        if (!$subject instanceof SavedSearch) {
  19. //            return false;
  20. //        }
  21.         return true;
  22.     }
  23.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  24.     {
  25.         $user $token->getUser();
  26.         if (!$user instanceof User) {
  27.             // the user must be logged in; if not, deny access
  28.             return false;
  29.         }
  30.         // you know $subject is a SavedSearch object, thanks to `supports()`
  31. //        /** @var SavedSearch $savedSearch */
  32. //        $savedSearch = $subject;
  33.         switch ($attribute) {
  34.             case self::ENTITY_TYPE_VIEW:
  35.                 return $this->canView($subject$user);
  36.         }
  37.         throw new LogicException('This code should not be reached!');
  38.     }
  39.     private function canView(mixed $subjectUser $user): bool
  40.     {
  41.         // TODO: Implement canView() method.
  42.         return false;
  43.     }
  44. }