src/Security/Voter/SouscriptionVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\TarifOffreCac;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. use App\Constants\TarifOffreCac as ConstantTarif;
  7. class SouscriptionVoter extends Voter {
  8. const CAN_SUBMIT_SOUSCRPTION = "can_submit_souscription";
  9. const IS_PERMANENT = 'is_permanent';
  10. const IS_PONCTUAL = 'is_ponctual';
  11. const ACTIONS = [
  12. self::IS_PERMANENT,
  13. self::IS_PONCTUAL
  14. ];
  15. protected function supports(string $attribute, $subject): bool
  16. {
  17. return in_array($attribute, self::ACTIONS);
  18. }
  19. protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token)
  20. {
  21. $oUser = $token->getUser();
  22. $oTarif = $subject;
  23. switch ($attribute) {
  24. case self::IS_PERMANENT:
  25. return $this->isPermanant($oTarif);
  26. default:
  27. throw new \LogicException('This code should not be reached!');
  28. }
  29. }
  30. private function isPermanant(TarifOffreCac $oTarif){
  31. return $oTarif->getBesoin() === ConstantTarif::PERMANENT_NEED;
  32. }
  33. }