<?php declare(strict_types=1);
namespace App\Security\Voter\Feed;
use App\Entity\Feed;
use App\Entity\User;
use App\Security\Voter\AbstractUserAwareVoter;
use App\Security\Voter\CreditsMembership\ContinuousMembership;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class ViewFeedItem extends AbstractUserAwareVoter
{
public const ATTRIBUTE = 'view_feed_item';
private AuthorizationCheckerInterface $authorizationChecker;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
protected function isGrantedForUser(object $object, User $user): bool
{
if (!$this->authorizationChecker->isGranted(ContinuousMembership::ATTRIBUTE, $object)) {
return false;
}
return null !== $user->getActiveCreditsMembership();
}
/**
* @return array<int, string>
*/
protected function getSupportedAttributes(): array
{
return [self::ATTRIBUTE];
}
protected function supportsObject(?object $object = null): bool
{
return $object instanceof Feed;
}
}