src/Lib/Payment/Voter/HasPaymentProcessVoter.php line 17

Open in your IDE?
  1. <?php
  2. /*
  3.  * Author: Dominik Piekarski <code@dompie.de>
  4.  * Created at: 2020/08/25 16:31
  5.  */
  6. declare(strict_types=1);
  7. namespace App\Lib\Payment\Voter;
  8. use App\Dictionary\Permission;
  9. use App\Entity\Account;
  10. use App\Entity\PaymentProcess;
  11. use App\Service\Payment\PaymentReferenceService;
  12. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  13. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  14. class HasPaymentProcessVoter extends Voter
  15. {
  16.     protected PaymentReferenceService $service;
  17.     public function __construct(PaymentReferenceService $service)
  18.     {
  19.         $this->service $service;
  20.     }
  21.     protected function supports(string $attribute$subject): bool
  22.     {
  23.         return Permission::ALLOWED_TO_BOOK === $attribute && $subject instanceof Account;
  24.     }
  25.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  26.     {
  27.         $process $this->service->findUnusedForMember($subject->getMember());
  28.         if (!$process instanceof PaymentProcess) {
  29.             throw PaymentVoterException::missingPaymentProcess();
  30.         }
  31.         return true;
  32.     }
  33. }