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