src/Point/Security/Voter/WalletVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Point\Security\Voter;
  4. use App\Point\Doctrine\Entity\Wallet;
  5. use App\Program\Doctrine\Entity\Profile;
  6. use App\Program\Doctrine\Entity\Program;
  7. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  8. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  9. final class WalletVoter extends Voter
  10. {
  11.     protected function supports(string $attributemixed $subject): bool
  12.     {
  13.         return $subject instanceof Wallet && 'item' === $attribute;
  14.     }
  15.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  16.     {
  17.         /** @var Wallet $wallet */
  18.         $wallet $subject;
  19.         /** @var Program $program */
  20.         $program $token->getUser();
  21.         /** @var Profile $profile */
  22.         $profile $wallet->getAccount()->getProfile();
  23.         return $profile->getProgram() === $program;
  24.     }
  25. }