vendor/nellapp/sdk-bundle/src/Permission/Security/Voter/ChannelUserMenuVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\Permission\Security\Voter;
  3. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserInterface;
  4. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  5. use Nellapp\Bundle\SDKBundle\Menu\Enum\ChannelMenuEnum;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class ChannelUserMenuVoter extends Voter
  9. {
  10.     public function supportsType(string $subjectType): bool
  11.     {
  12.         return is_subclass_of($subjectTypeChannelInterface::class);
  13.     }
  14.     public function supportsAttribute(string $attribute): bool
  15.     {
  16.         return in_array($attributeChannelMenuEnum::getChoices());
  17.     }
  18.     protected function supports(string $attribute$subject): bool
  19.     {
  20.         return $this->supportsType($subject::class) && $this->supportsAttribute($attribute);
  21.     }
  22.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  23.     {
  24.         $user $token->getUser();
  25.         if (!$user instanceof UserInterface) {
  26.             return false;
  27.         }
  28.         $channelUserData $user->getChannelUserDataByChannel($subject);
  29.         if (!$channelUserData || !$channelUserData->isActive()) {
  30.             return false;
  31.         }
  32.         return in_array($attribute$channelUserData->getDisplayedMenu());
  33.     }
  34. }