src/Voters/CompanyObjectsVoter.php line 15
<?php/** @author Guerby Duval <info@tranzaksyon.com>* @link https://tranzaksyon.com* @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.*/namespace App\Voters;use App\Interfaces\OwnerCompanyInterface;use App\Repository\UserRepository;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;class CompanyObjectsVoter extends Voter{const UPDATE = 'Update';const VIEW = 'View';public function __construct(private UserRepository $userRepository){}protected function supports(string $attribute, mixed $subject): bool{return in_array($attribute, [self::UPDATE, self::VIEW]) && $subject instanceof OwnerCompanyInterface;}protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool{$company = $this->userRepository->fetchSriInfo($token->getUser());$hasRole = false;if ($token->getUser() === null) {return false;}foreach ($token->getUser()->getRoles() as $role) {if ($role === 'ROLE_SELLER' || $role === 'ROLE_INVOICER' || $role === 'ROLE_ADMIN' || $role === 'ROLE_CHAT') {$hasRole = true;break;}}return $hasRole && $subject->getSriInfo() !== null && $subject->getSriInfo()->getId() === $company->getId();}}