<?php
namespace App\Security\Authorization\Voter;
use App\Entity\Setting;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class SettingVoter extends Voter
{
const READ = 'read';
const UPDATE = 'update';
/**
* {@inheritDoc}
*/
protected function supports($attribute, $subject)
{
$attributes = [
self::UPDATE,
];
if (!in_array($attribute, $attributes)) {
return false;
}
if (!$subject instanceof Setting) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
if ($user->isSuperAdmin()) {
return true;
}
return false;
}
}