<?php
namespace App\Security\Voter;
use App\Entity\MessageContent;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
class MessageContentVoter extends Voter
{
const DELETE = 'delete';
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
protected function supports($attribute, $subject)
{
if (!in_array($attribute, [self::DELETE])) {
return false;
}
if (!$subject instanceof MessageContent) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
/** @var MessageContent $messageContent */
$messageContent = $subject;
switch ($attribute) {
case self::DELETE:
return $this->canDelete($messageContent, $user, $token);
}
throw new \LogicException('This code should not be reached!');
}
private function canDelete(MessageContent $messageContent, User $user, TokenInterface $token)
{
return false;
}
}