fix return type for center resolver

This commit is contained in:
Julien Fastré 2021-11-22 12:22:28 +01:00
parent 4664394a89
commit fe3d4e1f0a
2 changed files with 14 additions and 3 deletions

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Security\Resolver; namespace Chill\MainBundle\Security\Resolver;
use Chill\MainBundle\Entity\Center;
final class CenterResolverManager implements CenterResolverManagerInterface final class CenterResolverManager implements CenterResolverManagerInterface
{ {
/** /**
@ -20,7 +22,17 @@ final class CenterResolverManager implements CenterResolverManagerInterface
{ {
foreach($this->resolvers as $resolver) { foreach($this->resolvers as $resolver) {
if ($resolver->supports($entity, $options)) { if ($resolver->supports($entity, $options)) {
return (array) $resolver->resolveCenter($entity, $options); $resolved = $resolver->resolveCenter($entity, $options);
if (null === $resolved) {
return [];
} elseif ($resolved instanceof Center) {
return [$resolved];
} elseif (\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)));
} }
} }

View File

@ -149,10 +149,9 @@
{% endif %} {% endif %}
</li> </li>
{% if options['addCenter'] and person|chill_resolve_center|length > 0 %} {% if options['addCenter'] and person|chill_resolve_center|length > 0 %}
{% set centers = person|chill_resolve_center %}
<li> <li>
<i class="fa fa-li fa-long-arrow-right"></i> <i class="fa fa-li fa-long-arrow-right"></i>
{% for c in centers %} {% for c in person|chill_resolve_center %}
{{ c.name|upper }}{% if not loop.last %}, {% endif %} {{ c.name|upper }}{% if not loop.last %}, {% endif %}
{% endfor %} {% endfor %}
</li> </li>