src/Security/Voter/RecruitmentCampaignVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\RecruitmentCampaign;
  4. use App\Features\RecruitmentCampaign\RecruitmentCampaignManager;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class RecruitmentCampaignVoter extends Voter
  8. {
  9.     public function __construct(private RecruitmentCampaignManager $campaignManager){}
  10.     public const CAMPAIGN_IS_SUBSCRIBABLE 'CAMPAIGN_IS_SUBSCRIBABLE';
  11.     protected function supports(string $attribute$subject): bool
  12.     {
  13.         return $attribute === self::CAMPAIGN_IS_SUBSCRIBABLE && $subject instanceof RecruitmentCampaign;
  14.     }
  15.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  16.     {
  17.         /* @var $subject RecruitmentCampaign */
  18.         return match ($attribute) {
  19.             self::CAMPAIGN_IS_SUBSCRIBABLE => $this->campaignManager->isCampaignSubscribable($subject),
  20.             default => false,
  21.         };
  22.     }
  23. }