mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +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
|
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
|
public function supports($attribute, $subject): bool
|
||||||
{
|
{
|
||||||
@ -37,7 +40,9 @@ final readonly class DefaultVoterHelper implements VoterHelperInterface
|
|||||||
|
|
||||||
public function voteOnAttribute($attribute, $subject, $token): bool
|
public function voteOnAttribute($attribute, $subject, $token): bool
|
||||||
{
|
{
|
||||||
if (!$token->getUser() instanceof User) {
|
$user = $token->getUser();
|
||||||
|
|
||||||
|
if (!$user instanceof User) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +51,7 @@ final readonly class DefaultVoterHelper implements VoterHelperInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->authorizationHelper->userHasAccess(
|
return $this->authorizationHelper->userHasAccess(
|
||||||
$token->getUser(),
|
$user,
|
||||||
$subject,
|
$subject,
|
||||||
$attribute
|
$attribute
|
||||||
);
|
);
|
||||||
|
@ -15,13 +15,12 @@ use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
|||||||
|
|
||||||
class DefaultVoterHelperFactory implements VoterHelperFactoryInterface
|
class DefaultVoterHelperFactory implements VoterHelperFactoryInterface
|
||||||
{
|
{
|
||||||
public function __construct(protected AuthorizationHelper $authorizationHelper, protected CenterResolverDispatcherInterface $centerResolverDispatcher) {}
|
public function __construct(protected AuthorizationHelper $authorizationHelper) {}
|
||||||
|
|
||||||
public function generate($context): VoterGeneratorInterface
|
public function generate($context): VoterGeneratorInterface
|
||||||
{
|
{
|
||||||
return new DefaultVoterHelperGenerator(
|
return new DefaultVoterHelperGenerator(
|
||||||
$this->authorizationHelper,
|
$this->authorizationHelper
|
||||||
$this->centerResolverDispatcher
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Security\Authorization;
|
namespace Chill\MainBundle\Security\Authorization;
|
||||||
|
|
||||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
|
||||||
|
|
||||||
final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
|
final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
|
||||||
{
|
{
|
||||||
private array $configuration = [];
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -30,7 +28,6 @@ final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
|
|||||||
{
|
{
|
||||||
return new DefaultVoterHelper(
|
return new DefaultVoterHelper(
|
||||||
$this->authorizationHelper,
|
$this->authorizationHelper,
|
||||||
$this->centerResolverDispatcher,
|
|
||||||
$this->configuration
|
$this->configuration
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,11 @@ class DefaultScopeResolver implements ScopeResolverInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw new UnexpectedValueException(
|
throw new UnexpectedValueException(
|
||||||
'should be an instanceof %s or %s',
|
sprintf(
|
||||||
HasScopesInterface::class,
|
'should be an instanceof %s or %s',
|
||||||
HasScopeInterface::class
|
HasScopesInterface::class,
|
||||||
|
HasScopeInterface::class
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user