<?php
namespace App\Security\Voter\Scholar\Manager;
use App\Entity\Channel\LockByInterface;
use App\Entity\Scholar\Lesson\Lesson;
use App\Entity\Scholar\Module\Module;
use App\Entity\Scholar\Training\Training;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class LockContentVoter extends Voter
{
const IS_NOT_LOCKED = 'IS_NOT_LOCKED';
public function supportsAttribute(string $attribute): bool
{
return $attribute === self::IS_NOT_LOCKED;
}
public function supportsType(string $subjectType): bool
{
return is_subclass_of($subjectType, Training::class)
|| is_subclass_of($subjectType, Module::class)
|| is_subclass_of($subjectType, Lesson::class)
;
}
protected function supports(string $attribute, $subject): bool
{
return $this->supportsAttribute($attribute) && $this->supportsType($subject::class);
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
return !$subject instanceof LockByInterface;
}
}