vendor/nellapp/sdk-bundle/src/Permission/Security/Voter/UserOwnerVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\Permission\Security\Voter;
  3. use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerGetter;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. class UserOwnerVoter extends Voter
  7. {
  8.     const USER_OWNER 'USER_OWNER';
  9.     public function __construct(
  10.         private UserOwnerGetter $userOwnerGetter,
  11.     ) {}
  12.     public function supportsType(string $subjectType): bool
  13.     {
  14.         return $this->userOwnerGetter->supportsType($subjectType);
  15.     }
  16.     public function supportsAttribute(string $attribute): bool
  17.     {
  18.         return $attribute === self::USER_OWNER;
  19.     }
  20.     protected function supports(string $attribute$subject): bool
  21.     {
  22.         return $this->supportsAttribute($attribute) && $this->supportsType($subject::class);
  23.     }
  24.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  25.     {
  26.         $user $token->getUser();
  27.         if ($user === null) {
  28.             return false;
  29.         }
  30.         return $this->userOwnerGetter->isOwnerOf($user$subject);
  31.     }
  32. }