src/Security/ProjectSaleVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use App\Modules\Order\Entity\ProjectSale;
  4. use App\Entity\Project\Corporate\Corporate;
  5. use App\Entity\User;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class ProjectSaleVoter extends Voter
  9. {
  10.     const ATTRIBUTES = [self::ATTR_POSTPAY];
  11.     const ATTR_POSTPAY 'SALE_POSTPAY';
  12.     /**
  13.      * Determines if the attribute and subject are supported by this voter.
  14.      *
  15.      * @param string $attribute An attribute
  16.      * @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
  17.      *
  18.      * @return bool True if the attribute and subject are supported, false otherwise
  19.      */
  20.     protected function supports($attribute$subject)
  21.     {
  22.         return $subject instanceof ProjectSale && in_array($attribute, static::ATTRIBUTES);
  23.     }
  24.     /**
  25.      * Perform a single access check operation on a given attribute, subject and token.
  26.      * It is safe to assume that $attribute and $subject already passed the "supports()" method check.
  27.      *
  28.      * @param string $attribute
  29.      * @param mixed $subject
  30.      * @param TokenInterface $token
  31.      *
  32.      * @return bool
  33.      */
  34.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  35.     {
  36.         /**
  37.          * @var \App\Modules\Order\Entity\ProjectSale $subject
  38.          * @var User                                  $user
  39.          */
  40.         $user $token->getUser();
  41.         switch ($attribute) {
  42.             case static::ATTR_POSTPAY:
  43. //                $vote = ($user === $subject->getClient() &&
  44. //                    ($subject->getProject() instanceof Corporate or $user->getFlexPayment()));
  45.                 $vote $user === $subject->getClient();
  46.                 break;
  47.             default:
  48.                 $vote false;
  49.         }
  50.         return $vote;
  51.     }
  52. }