src/App/Security/Voter/CreditsMembership/ContinuousMembership.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Security\Voter\CreditsMembership;
  3. use App\Contract\Payments\MembershipLimitedContent;
  4. use App\Entity\User;
  5. use App\Security\Voter\AbstractUserAwareVoter;
  6. use App\Service\MembershipStart;
  7. use function assert;
  8. class ContinuousMembership extends AbstractUserAwareVoter
  9. {
  10.     public const ATTRIBUTE 'continuous_membership';
  11.     private MembershipStart $membershipStart;
  12.     public function __construct(MembershipStart $membershipStart)
  13.     {
  14.         $this->membershipStart $membershipStart;
  15.     }
  16.     /**
  17.      * @param MembershipLimitedContent|object $object
  18.      */
  19.     protected function isGrantedForUser(object $objectUser $user): bool
  20.     {
  21.         assert($object instanceof MembershipLimitedContent);
  22.         $startDate $this->membershipStart->getContentViewStart($user);
  23.         return null !== $object->getActivateDate() && $startDate <= $object->getActivateDate();
  24.     }
  25.     /**
  26.      * @return array<int, string>
  27.      */
  28.     protected function getSupportedAttributes(): array
  29.     {
  30.         return [self::ATTRIBUTE];
  31.     }
  32.     protected function supportsObject(?object $object null): bool
  33.     {
  34.         return $object instanceof MembershipLimitedContent;
  35.     }
  36. }