mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-08 07:44:59 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
<?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;
|
||||
|
||||
|
||||
final class CenterResolverDispatcher implements CenterResolverDispatcherInterface
|
||||
{
|
||||
/**
|
||||
@@ -29,7 +35,7 @@ final class CenterResolverDispatcher implements CenterResolverDispatcherInterfac
|
||||
'
|
||||
);
|
||||
|
||||
foreach($this->resolvers as $resolver) {
|
||||
foreach ($this->resolvers as $resolver) {
|
||||
if ($resolver->supports($entity, $options)) {
|
||||
return $resolver->resolveCenter($entity, $options);
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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;
|
||||
@@ -13,7 +20,8 @@ interface CenterResolverDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* @param object $entity
|
||||
* @return null|Center|Center[]
|
||||
*
|
||||
* @return Center|Center[]|null
|
||||
*/
|
||||
public function resolveCenter($entity, ?array $options = []);
|
||||
}
|
||||
|
@@ -1,21 +1,29 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
|
||||
interface CenterResolverInterface
|
||||
{
|
||||
/**
|
||||
* @param object $entity
|
||||
*/
|
||||
public function supports($entity, ?array $options = []): bool;
|
||||
public static function getDefaultPriority(): int;
|
||||
|
||||
/**
|
||||
* @param object $entity
|
||||
*
|
||||
* @return Center|Center[]
|
||||
*/
|
||||
public function resolveCenter($entity, ?array $options = []);
|
||||
|
||||
public static function getDefaultPriority(): int;
|
||||
/**
|
||||
* @param object $entity
|
||||
*/
|
||||
public function supports($entity, ?array $options = []): bool;
|
||||
}
|
||||
|
@@ -1,10 +1,19 @@
|
||||
<?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\Center;
|
||||
use UnexpectedValueException;
|
||||
use function is_array;
|
||||
|
||||
final class CenterResolverManager implements CenterResolverManagerInterface
|
||||
{
|
||||
@@ -20,19 +29,28 @@ final class CenterResolverManager implements CenterResolverManagerInterface
|
||||
|
||||
public function resolveCenters($entity, ?array $options = []): array
|
||||
{
|
||||
foreach($this->resolvers as $resolver) {
|
||||
foreach ($this->resolvers as $resolver) {
|
||||
if ($resolver->supports($entity, $options)) {
|
||||
$resolved = $resolver->resolveCenter($entity, $options);
|
||||
|
||||
if (null === $resolved) {
|
||||
return [];
|
||||
} elseif ($resolved instanceof Center) {
|
||||
}
|
||||
|
||||
if ($resolved instanceof Center) {
|
||||
return [$resolved];
|
||||
} elseif (\is_array($resolved)) {
|
||||
}
|
||||
|
||||
if (is_array($resolved)) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException(sprintf("the return type of a %s should be an instance of %s, an array or null. Resolver is %s",
|
||||
CenterResolverInterface::class, Center::class, get_class($resolver)));
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'the return type of a %s should be an instance of %s, an array or null. Resolver is %s',
|
||||
CenterResolverInterface::class,
|
||||
Center::class,
|
||||
get_class($resolver)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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;
|
||||
@@ -10,6 +17,7 @@ interface CenterResolverManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param object $entity
|
||||
*
|
||||
* @return Center[]
|
||||
*/
|
||||
public function resolveCenters($entity, ?array $options = []): array;
|
||||
|
@@ -1,21 +1,26 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\HasCenterInterface;
|
||||
use Chill\MainBundle\Entity\HasCentersInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class DefaultCenterResolver implements CenterResolverInterface
|
||||
{
|
||||
public function supports($entity, ?array $options = []): bool
|
||||
public static function getDefaultPriority(): int
|
||||
{
|
||||
return $entity instanceof HasCenterInterface || $entity instanceof HasCentersInterface;
|
||||
return -256;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param HasCenterInterface $entity
|
||||
* @param array $options
|
||||
*/
|
||||
@@ -23,15 +28,17 @@ class DefaultCenterResolver implements CenterResolverInterface
|
||||
{
|
||||
if ($entity instanceof HasCenterInterface) {
|
||||
return $entity->getCenter();
|
||||
} elseif ($entity instanceof HasCentersInterface) {
|
||||
return $entity->getCenters();
|
||||
} else {
|
||||
throw new \UnexpectedValueException("should be an instanceof");
|
||||
}
|
||||
|
||||
if ($entity instanceof HasCentersInterface) {
|
||||
return $entity->getCenters();
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('should be an instanceof');
|
||||
}
|
||||
|
||||
public static function getDefaultPriority(): int
|
||||
public function supports($entity, ?array $options = []): bool
|
||||
{
|
||||
return -256;
|
||||
return $entity instanceof HasCenterInterface || $entity instanceof HasCentersInterface;
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +1,23 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\HasScopeInterface;
|
||||
use Chill\MainBundle\Entity\HasScopesInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class DefaultScopeResolver implements ScopeResolverInterface
|
||||
{
|
||||
|
||||
public function supports($entity, ?array $options = []): bool
|
||||
public static function getDefaultPriority(): int
|
||||
{
|
||||
return $entity instanceof HasScopeInterface || $entity instanceof HasScopesInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param HasScopeInterface|HasScopesInterface $entity
|
||||
*/
|
||||
public function resolveScope($entity, ?array $options = [])
|
||||
{
|
||||
if ($entity instanceof HasScopeInterface) {
|
||||
return $entity->getScope();
|
||||
} elseif ($entity instanceof HasScopesInterface) {
|
||||
return $entity->getScopes();
|
||||
} else {
|
||||
throw new \UnexpectedValueException("should be an instanceof %s or %s",
|
||||
HasScopesInterface::class, HasScopeInterface::class);
|
||||
}
|
||||
return -256;
|
||||
}
|
||||
|
||||
public function isConcerned($entity, ?array $options = []): bool
|
||||
@@ -35,8 +25,28 @@ class DefaultScopeResolver implements ScopeResolverInterface
|
||||
return $entity instanceof HasScopeInterface || $entity instanceof HasScopesInterface;
|
||||
}
|
||||
|
||||
public static function getDefaultPriority(): int
|
||||
/**
|
||||
* @param HasScopeInterface|HasScopesInterface $entity
|
||||
*/
|
||||
public function resolveScope($entity, ?array $options = [])
|
||||
{
|
||||
return -256;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Twig\TwigFilter;
|
||||
@@ -7,6 +14,7 @@ use Twig\TwigFilter;
|
||||
final class ResolverTwigExtension extends \Twig\Extension\AbstractExtension
|
||||
{
|
||||
private CenterResolverManagerInterface $centerResolverDispatcher;
|
||||
|
||||
private ScopeResolverDispatcher $scopeResolverDispatcher;
|
||||
|
||||
public function __construct(CenterResolverManagerInterface $centerResolverDispatcher, ScopeResolverDispatcher $scopeResolverDispatcher)
|
||||
@@ -24,9 +32,19 @@ final class ResolverTwigExtension extends \Twig\Extension\AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScopeConcerned($entity, ?array $options = [])
|
||||
{
|
||||
return $this->scopeResolverDispatcher->isConcerned($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $entity
|
||||
* @param array|null $options
|
||||
*
|
||||
* @return Center|Center[]|null
|
||||
*/
|
||||
public function resolveCenter($entity, ?array $options = [])
|
||||
@@ -36,17 +54,7 @@ final class ResolverTwigExtension extends \Twig\Extension\AbstractExtension
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array|null $options
|
||||
* @return bool
|
||||
*/
|
||||
public function isScopeConcerned($entity, ?array $options = [])
|
||||
{
|
||||
return $this->scopeResolverDispatcher->isConcerned($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array|null $options
|
||||
*
|
||||
* @return array|\Chill\MainBundle\Entity\Scope|\Chill\MainBundle\Entity\Scope[]
|
||||
*/
|
||||
public function resolveScope($entity, ?array $options = [])
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
@@ -16,9 +23,21 @@ final class ScopeResolverDispatcher
|
||||
$this->resolvers = $resolvers;
|
||||
}
|
||||
|
||||
public function isConcerned($entity, ?array $options = []): bool
|
||||
{
|
||||
foreach ($this->resolvers as $resolver) {
|
||||
if ($resolver->supports($entity, $options)) {
|
||||
return $resolver->isConcerned($entity, $options);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @return Scope|Scope[]|iterable
|
||||
*
|
||||
* @return iterable|Scope|Scope[]
|
||||
*/
|
||||
public function resolveScope($entity, ?array $options = [])
|
||||
{
|
||||
@@ -30,15 +49,4 @@ final class ScopeResolverDispatcher
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isConcerned($entity, ?array $options = []): bool
|
||||
{
|
||||
foreach ($this->resolvers as $resolver) {
|
||||
if ($resolver->supports($entity, $options)) {
|
||||
return $resolver->isConcerned($entity, $options);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
@@ -9,27 +16,32 @@ use Chill\MainBundle\Entity\Scope;
|
||||
*/
|
||||
interface ScopeResolverInterface
|
||||
{
|
||||
/**
|
||||
* Return true if this resolve is able to decide "something" on this entity.
|
||||
*/
|
||||
public function supports($entity, ?array $options = []): bool;
|
||||
|
||||
/**
|
||||
* Will return the scope for the entity
|
||||
*
|
||||
* @return Scope|array|Scope[]
|
||||
*/
|
||||
public function resolveScope($entity, ?array $options = []);
|
||||
|
||||
|
||||
/**
|
||||
* Return true if the entity is concerned by scope, false otherwise.
|
||||
*/
|
||||
public function isConcerned($entity, ?array $options = []): bool;
|
||||
|
||||
/**
|
||||
* get the default priority for this resolver. Resolver with an higher priority will be
|
||||
* queried first.
|
||||
*/
|
||||
public static function getDefaultPriority(): int;
|
||||
|
||||
/**
|
||||
* Return true if the entity is concerned by scope, false otherwise.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function isConcerned($entity, ?array $options = []): bool;
|
||||
|
||||
/**
|
||||
* Will return the scope for the entity.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*
|
||||
* @return array|Scope|Scope[]
|
||||
*/
|
||||
public function resolveScope($entity, ?array $options = []);
|
||||
|
||||
/**
|
||||
* Return true if this resolve is able to decide "something" on this entity.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function supports($entity, ?array $options = []): bool;
|
||||
}
|
||||
|
Reference in New Issue
Block a user