vendor/nellapp/sdk-bundle/src/Developers/Security/Voter/ChannelScopeVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\Developers\Security\Voter;
  3. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  4. use Nellapp\Bundle\SDKBundle\Developers\ChannelScopeAuthorisationService;
  5. use Nellapp\Bundle\SDKBundle\GlobalGetters\Service\ConfigurationService;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  9. class ChannelScopeVoter extends Voter
  10. {
  11.     public function __construct(
  12.         private ChannelScopeAuthorisationService $channelScopeAuthorisationService,
  13.         private ConfigurationService $configurationService,
  14.     ) {}
  15.     protected function supports($attribute, $subject): bool
  16.     {
  17.         return is_string($attribute)
  18.             && str_starts_with($attribute, 'channel:')
  19.             && $subject instanceof ChannelInterface;
  20.     }
  21.     protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
  22.     {
  23.         if (!$this->configurationService->getConfiguration($subject)?->isEnableDevelopersApi()) {
  24.             throw new NotFoundHttpException();
  25.         }
  26.         return $this->channelScopeAuthorisationService->canAccess($attribute, $subject);
  27.     }
  28. }