src/Security/Authorization/Voter/EditVehicleVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Security\Authorization\Voter;
  3. use App\Entity\User;
  4. use App\Entity\Vehicle;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class EditVehicleVoter extends Voter
  9. {
  10.     public const EDIT 'edit';
  11.     public function __construct(private readonly AccessDecisionManagerInterface $decisionManager)
  12.     {
  13.     }
  14.     protected function supports($attribute$subject)
  15.     {
  16.         if (self::EDIT !== $attribute) {
  17.             return false;
  18.         }
  19.         if (!$subject instanceof Vehicle) {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  25.     {
  26.         return $this->decisionManager->decide($token, ['ROLE_SALESPERSON'])
  27.         || $this->decisionManager->decide($token, ['ROLE_LIVE_OPERATOR'])
  28.         || $this->decisionManager->decide($token, ['ROLE_LIVE_AUCTIONEER']);
  29.     }
  30. }