mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Remove unused dependency on DefaultVoter (+ fix when throwing an exception)
This commit is contained in:
parent
d3b68f8f8f
commit
cd9611a669
@ -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
|
||||
);
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user