<?php
namespace AppBundle\Security;
use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class WamVoter extends Voter
{
public const IS_WAM_USER = 'IS_WAM_USER';
public const IS_NOT_WAM_USER = 'IS_NOT_WAM_USER';
protected function supports($attribute, $subject)
{
return in_array($attribute, [self::IS_WAM_USER, self::IS_NOT_WAM_USER], true);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
$isWamUser = (null !== $user->getLawFirm()?->getEcmId());
if (self::IS_WAM_USER === $attribute) {
return $isWamUser;
}
return !$isWamUser;
}
}