Remove unused dependency on DefaultVoter (+ fix when throwing an exception)

This commit is contained in:
Julien Fastré 2023-09-13 10:09:42 +02:00
parent d3b68f8f8f
commit cd9611a669
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 18 additions and 15 deletions

View File

@ -18,7 +18,10 @@ use function in_array;
final readonly class DefaultVoterHelper implements VoterHelperInterface
{
public function __construct(private AuthorizationHelper $authorizationHelper, private CenterResolverDispatcherInterface $centerResolverDispatcher, private array $configuration) {}
public function __construct(
private AuthorizationHelper $authorizationHelper,
private array $configuration
) {}
public function supports($attribute, $subject): bool
{
@ -37,7 +40,9 @@ final readonly class DefaultVoterHelper implements VoterHelperInterface
public function voteOnAttribute($attribute, $subject, $token): bool
{
if (!$token->getUser() instanceof User) {
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
@ -46,7 +51,7 @@ final readonly class DefaultVoterHelper implements VoterHelperInterface
}
return $this->authorizationHelper->userHasAccess(
$token->getUser(),
$user,
$subject,
$attribute
);

View File

@ -15,13 +15,12 @@ use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
class DefaultVoterHelperFactory implements VoterHelperFactoryInterface
{
public function __construct(protected AuthorizationHelper $authorizationHelper, protected CenterResolverDispatcherInterface $centerResolverDispatcher) {}
public function __construct(protected AuthorizationHelper $authorizationHelper) {}
public function generate($context): VoterGeneratorInterface
{
return new DefaultVoterHelperGenerator(
$this->authorizationHelper,
$this->centerResolverDispatcher
$this->authorizationHelper
);
}
}

View File

@ -11,17 +11,15 @@ declare(strict_types=1);
namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
{
private array $configuration = [];
public function __construct(private readonly AuthorizationHelper $authorizationHelper, private readonly CenterResolverDispatcherInterface $centerResolverDispatcher) {}
public function __construct(private readonly AuthorizationHelper $authorizationHelper) {}
public function addCheckFor(?string $subject, array $attributes): self
public function addCheckFor(?string $class, array $attributes): self
{
$this->configuration[] = [$attributes, $subject];
$this->configuration[] = [$attributes, $class];
return $this;
}
@ -30,7 +28,6 @@ final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
{
return new DefaultVoterHelper(
$this->authorizationHelper,
$this->centerResolverDispatcher,
$this->configuration
);
}

View File

@ -41,9 +41,11 @@ class DefaultScopeResolver implements ScopeResolverInterface
}
throw new UnexpectedValueException(
'should be an instanceof %s or %s',
HasScopesInterface::class,
HasScopeInterface::class
sprintf(
'should be an instanceof %s or %s',
HasScopesInterface::class,
HasScopeInterface::class
)
);
}