vendor/serglobin/chat-gpt-bundle/src/Security/ChatGptVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Serglobin\ChatGptBundle\Security;
  4. use Serglobin\ChatGptBundle\Contracts\ChatGptUserInfoInterface;
  5. use Symfony\Component\Security\Core\Security;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class ChatGptVoter extends Voter
  9. {
  10.     public const VOTER_ATTRIBUTE 'CHAT_GPT';
  11.     public function __construct(
  12.         private readonly Security $security,
  13.     ) {
  14.     }
  15.     protected function supports(string $attributemixed $subject): bool
  16.     {
  17.         return self::VOTER_ATTRIBUTE === $attribute;
  18.     }
  19.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  20.     {
  21.         $user $token->getUser();
  22.         if (!$user instanceof ChatGptUserInfoInterface) {
  23.             return false;
  24.         }
  25.         if (!$this->security->isGranted('IS_AUTHENTICATED_FULLY')) {
  26.             return false;
  27.         }
  28.         if (!$user->isVirtualAssistantActive()) {
  29.             return false;
  30.         }
  31.         return true;
  32.     }
  33. }