mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix: Add a deprecation and the new service that goes with it as replacement.
This commit is contained in:
parent
370a24d3f5
commit
674bf614dd
@ -1,27 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
class CenterResolverDispatcher
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
|
||||
/**
|
||||
* @deprecated Use CenterResolverManager and its interface CenterResolverManagerInterface
|
||||
*/
|
||||
final class CenterResolverDispatcher
|
||||
{
|
||||
/**
|
||||
* @var iterabble|CenterResolverInterface[]
|
||||
* @var CenterResolverInterface[]
|
||||
*/
|
||||
private iterable $resolvers = [];
|
||||
private iterable $resolvers;
|
||||
|
||||
public function __construct(iterable $resolvers)
|
||||
public function __construct(iterable $resolvers = [])
|
||||
{
|
||||
$this->resolvers = $resolvers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $entity
|
||||
* @param array|null $options
|
||||
* @return null|Center|Center[]
|
||||
*/
|
||||
public function resolveCenter($entity, ?array $options = [])
|
||||
{
|
||||
foreach($this->resolvers as $priority => $resolver) {
|
||||
trigger_deprecation(
|
||||
'ChillMainBundle',
|
||||
'dev-master',
|
||||
'
|
||||
Use the service CenterResolverManager through the interface CenterResolverManagerInterface.
|
||||
The new method "CenterResolverManagerInterface::resolveCenters(): array" is available and the typing
|
||||
has been improved in order to avoid mixing types.
|
||||
'
|
||||
);
|
||||
|
||||
foreach($this->resolvers as $resolver) {
|
||||
if ($resolver->supports($entity, $options)) {
|
||||
return $resolver->resolveCenter($entity, $options);
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
|
||||
final class CenterResolverManager implements CenterResolverManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var CenterResolverInterface[]
|
||||
*/
|
||||
private iterable $resolvers;
|
||||
|
||||
public function __construct(iterable $resolvers = [])
|
||||
{
|
||||
$this->resolvers = $resolvers;
|
||||
}
|
||||
|
||||
public function resolveCenters($entity, ?array $options = []): array
|
||||
{
|
||||
foreach($this->resolvers as $resolver) {
|
||||
if ($resolver->supports($entity, $options)) {
|
||||
return (array) $resolver->resolveCenter($entity, $options);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Security\Resolver;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
|
||||
interface CenterResolverManagerInterface
|
||||
{
|
||||
/**
|
||||
* @return Center[]
|
||||
*/
|
||||
public function resolveCenters($entity, ?array $options = []): array;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user