<?php
namespace Nellapp\Bundle\SDKBundle\Developers\Security\Voter;
use Nellapp\Bundle\SDKBundle\Developers\GlobalScopeAuthorizationService;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class GlobalScopeVoter extends Voter
{
public function __construct(
private GlobalScopeAuthorizationService $authorizationService,
) {
}
public function supportsType(string $subjectType): bool
{
return true;
}
public function supportsAttribute(string $attribute): bool
{
return is_string($attribute)
&& str_starts_with($attribute, 'global:');
}
protected function supports($attribute, $subject): bool
{
return $this->supportsAttribute($attribute) && $this->supportsType('');
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
return $this->authorizationService->canAccess($attribute);
}
}