mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\MainBundle\Security\Resolver;
|
|
|
|
use Chill\MainBundle\Entity\HasScopeInterface;
|
|
use Chill\MainBundle\Entity\HasScopesInterface;
|
|
use UnexpectedValueException;
|
|
|
|
class DefaultScopeResolver implements ScopeResolverInterface
|
|
{
|
|
public static function getDefaultPriority(): int
|
|
{
|
|
return -256;
|
|
}
|
|
|
|
public function isConcerned($entity, ?array $options = []): bool
|
|
{
|
|
return $entity instanceof HasScopeInterface || $entity instanceof HasScopesInterface;
|
|
}
|
|
|
|
/**
|
|
* @param HasScopeInterface|HasScopesInterface $entity
|
|
*/
|
|
public function resolveScope($entity, ?array $options = [])
|
|
{
|
|
if ($entity instanceof HasScopeInterface) {
|
|
return $entity->getScope();
|
|
}
|
|
|
|
if ($entity instanceof HasScopesInterface) {
|
|
return $entity->getScopes();
|
|
}
|
|
|
|
throw new UnexpectedValueException(
|
|
'should be an instanceof %s or %s',
|
|
HasScopesInterface::class,
|
|
HasScopeInterface::class
|
|
);
|
|
}
|
|
|
|
public function supports($entity, ?array $options = []): bool
|
|
{
|
|
return $entity instanceof HasScopeInterface || $entity instanceof HasScopesInterface;
|
|
}
|
|
}
|