src/Notification/Security/Notification/Voter.php line 29
<?phpdeclare(strict_types=1);/*** Copyright (c) 2021 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2021 TECLA Consulting Group oü*/namespace App\Notification\Security\Notification;use App\Core\Security\ContactAwareSubjectInterface;use App\Notification\Model\NotificationInterface;use InvalidArgumentException;use LogicException;use Symfony\Component\DependencyInjection\ServiceLocator;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter as BaseVoter;final class Voter extends BaseVoter{private ServiceLocator $permissions;public function __construct(ServiceLocator $permissions){$this->permissions = $permissions;}protected function supports(string $attribute, $subject): bool{return$this->permissions->has($attribute) &&true === $subject instanceof ContactAwareSubjectInterface &&(null === $subject->getSubject() || (true === $subject->getSubject() instanceof NotificationInterface));}protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool{if (false === $subject instanceof ContactAwareSubjectInterface) {throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given', ContactAwareSubjectInterface::class, get_debug_type($subject)));}$contact = $subject->getContact();$notification = $subject->getSubject();if (null !== $notification && false === $notification instanceof NotificationInterface) {throw new InvalidArgumentException(sprintf('Expected subject of type "%s", "%s" given', NotificationInterface::class, get_debug_type($notification)));}/** @var PermissionInterface $permission */$permission = ($this->permissions)($attribute);if (null !== $permission) {return $permission->isGranted($contact, $notification);}throw new LogicException('This code should not be reached!');}}