<?php
namespace AppBundle\Services\Voter;
use AppBundle\Entity\Website;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class WebsiteVoter extends Voter
{
public const VIEW = 'view';
public const EDIT = 'edit';
protected function supports($attribute, $subject)
{
// if the attribute isn't one we support, return false
if (!in_array($attribute, [self::VIEW, self::EDIT])) {
return false;
}
// only vote on Post objects inside this voter
if (!$subject instanceof Website) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $website, TokenInterface $token)
{
$user = $token->getUser();
// To do : show if active else show only if user is owner
if ($attribute == self::VIEW && $website == $user) {
return true;
}
// To do : edit only if user is owner
if ($attribute == self::EDIT && $website == $user) {
return true;
}
return false;
}
}