<?php declare(strict_types=1);
namespace App\Security\Voter\CreditsMembership;
use App\Contract\Payments\MembershipLimitedContent;
use App\Entity\User;
use App\Security\Voter\AbstractUserAwareVoter;
use App\Service\MembershipStart;
use function assert;
class ContinuousMembership extends AbstractUserAwareVoter
{
public const ATTRIBUTE = 'continuous_membership';
private MembershipStart $membershipStart;
public function __construct(MembershipStart $membershipStart)
{
$this->membershipStart = $membershipStart;
}
/**
* @param MembershipLimitedContent|object $object
*/
protected function isGrantedForUser(object $object, User $user): bool
{
assert($object instanceof MembershipLimitedContent);
$startDate = $this->membershipStart->getContentViewStart($user);
return null !== $object->getActivateDate() && $startDate <= $object->getActivateDate();
}
/**
* @return array<int, string>
*/
protected function getSupportedAttributes(): array
{
return [self::ATTRIBUTE];
}
protected function supportsObject(?object $object = null): bool
{
return $object instanceof MembershipLimitedContent;
}
}