<?php
namespace App\Security\Voter\Channel;
use App\Entity\Channel\Channel;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* TODO Generalize Voter to manage available actions for given Channel
* => Only share Content for the moment
*/
class CanShareContentVoter extends Voter
{
const CHANNEL_PERM_SHARE_CONTENT = 'CHANNEL_PERM_SHARE_CONTENT';
public function supportsAttribute(string $attribute): bool
{
return $attribute === self::CHANNEL_PERM_SHARE_CONTENT;
}
public function supportsType(string $subjectType): bool
{
return $subjectType === Channel::class;
}
function supports(string $attribute, $subject): bool
{
return $this->supportsType($subject::class) && $this->supportsAttribute($attribute);
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
if ($subject->isCanShareContent()) {
return true;
}
return false;
}
}