src/Note/Security/Note/Voter.php line 25

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2023 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2023 TECLA Consulting Group oü
  16.  */
  17. namespace App\Note\Security\Note;
  18. use Symfony\Component\DependencyInjection\ServiceLocator;
  19. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  20. use Symfony\Component\Security\Core\Authorization\Voter\Voter as BaseVoter;
  21. final class Voter extends BaseVoter
  22. {
  23.     private ServiceLocator $permissions;
  24.     public function __construct(ServiceLocator $permissions)
  25.     {
  26.         $this->permissions $permissions;
  27.     }
  28.     public function supportsAttribute(string $attribute): bool
  29.     {
  30.         return $this->permissions->has($attribute);
  31.     }
  32.     protected function supports(string $attribute$subject): bool
  33.     {
  34.         return $this->supportsAttribute($attribute);
  35.     }
  36.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  37.     {
  38.         /** @var PermissionInterface $permission */
  39.         $permission = ($this->permissions)($attribute);
  40.         if (null !== $permission) {
  41.             return $permission->isGranted($subject);
  42.         }
  43.         throw new \LogicException('This code should not be reached!');
  44.     }
  45. }