src/Security/IsCustomerVoter.php line 11

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security;
  4. use App\Entity\System\Customer;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class IsCustomerVoter extends Voter
  8. {
  9. public const IS_CUSTOMER = 'IS_CUSTOMER';
  10. protected function supports($attribute, $subject): bool
  11. {
  12. return $attribute === self::IS_CUSTOMER;
  13. }
  14. protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
  15. {
  16. $user = $token->getUser();
  17. if (!$user instanceof Customer) {
  18. return false;
  19. }
  20. return true;
  21. }
  22. }