mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-05 08:26:13 +00:00
67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* 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;
|
|
|
|
final class ResolverTwigExtension extends \Twig\Extension\AbstractExtension
|
|
{
|
|
private CenterResolverManagerInterface $centerResolverDispatcher;
|
|
|
|
private ScopeResolverDispatcher $scopeResolverDispatcher;
|
|
|
|
public function __construct(CenterResolverManagerInterface $centerResolverDispatcher, ScopeResolverDispatcher $scopeResolverDispatcher)
|
|
{
|
|
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
|
$this->scopeResolverDispatcher = $scopeResolverDispatcher;
|
|
}
|
|
|
|
public function getFilters()
|
|
{
|
|
return [
|
|
new TwigFilter('chill_resolve_center', [$this, 'resolveCenter']),
|
|
new TwigFilter('chill_resolve_scope', [$this, 'resolveScope']),
|
|
new TwigFilter('chill_is_scope_concerned', [$this, 'isScopeConcerned']),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param $entity
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isScopeConcerned($entity, ?array $options = [])
|
|
{
|
|
return $this->scopeResolverDispatcher->isConcerned($entity, $options);
|
|
}
|
|
|
|
/**
|
|
* @param mixed $entity
|
|
*
|
|
* @return Center|Center[]|null
|
|
*/
|
|
public function resolveCenter($entity, ?array $options = [])
|
|
{
|
|
return $this->centerResolverDispatcher->resolveCenters($entity, $options);
|
|
}
|
|
|
|
/**
|
|
* @param $entity
|
|
*
|
|
* @return array|\Chill\MainBundle\Entity\Scope|\Chill\MainBundle\Entity\Scope[]
|
|
*/
|
|
public function resolveScope($entity, ?array $options = [])
|
|
{
|
|
return $this->scopeResolverDispatcher->resolveScope();
|
|
}
|
|
}
|