vendor/ezsystems/ezplatform-kernel/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/ConfigResolver/SiteAccessGroupConfigResolver.php line 21

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver;
  8. use eZ\Publish\Core\MVC\Exception\ParameterNotFoundException;
  9. use eZ\Publish\Core\MVC\Symfony\SiteAccess;
  10. use eZ\Publish\Core\MVC\Symfony\SiteAccessGroup;
  11. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  12. /**
  13.  * @property-read \Symfony\Component\DependencyInjection\ContainerInterface $container
  14.  *
  15.  * @internal
  16.  */
  17. class SiteAccessGroupConfigResolver extends SiteAccessConfigResolver
  18. {
  19.     use ContainerAwareTrait;
  20.     /** @var string[][] */
  21.     protected $siteAccessGroups;
  22.     public function __construct(
  23.         SiteAccess\SiteAccessProviderInterface $siteAccessProvider,
  24.         string $defaultNamespace,
  25.         array $siteAccessGroups
  26.     ) {
  27.         parent::__construct($siteAccessProvider$defaultNamespace);
  28.         $this->siteAccessGroups $siteAccessGroups;
  29.     }
  30.     final public function hasParameter(string $paramName, ?string $namespace null, ?string $scope null): bool
  31.     {
  32.         [$namespace$scope] = $this->resolveNamespaceAndScope($namespace$scope);
  33.         if ($this->isSiteAccessGroupScope($scope)) {
  34.             return $this->resolverHasParameterForGroup(new SiteAccessGroup($scope), $paramName$namespace);
  35.         }
  36.         return parent::hasParameter($paramName$namespace$scope);
  37.     }
  38.     final public function getParameter(string $paramName, ?string $namespace null, ?string $scope null)
  39.     {
  40.         [$namespace$scope] = $this->resolveNamespaceAndScope($namespace$scope);
  41.         if ($this->isSiteAccessGroupScope($scope)) {
  42.             return $this->getParameterFromResolverForGroup(new SiteAccessGroup($scope), $paramName$namespace);
  43.         }
  44.         return parent::getParameter($paramName$namespace$scope);
  45.     }
  46.     protected function resolverHasParameter(SiteAccess $siteAccessstring $paramNamestring $namespace): bool
  47.     {
  48.         foreach ($siteAccess->groups as $group) {
  49.             $groupScopeParamName $this->resolveScopeRelativeParamName($paramName$namespace$group->getName());
  50.             if ($this->container->hasParameter($groupScopeParamName)) {
  51.                 return true;
  52.             }
  53.         }
  54.         return false;
  55.     }
  56.     protected function resolverHasParameterForGroup(SiteAccessGroup $siteAccessGroupstring $paramNamestring $namespace): bool
  57.     {
  58.         $groupScopeParamName $this->resolveScopeRelativeParamName($paramName$namespace$siteAccessGroup->getName());
  59.         return $this->container->hasParameter($groupScopeParamName);
  60.     }
  61.     protected function getParameterFromResolver(SiteAccess $siteAccessstring $paramNamestring $namespace)
  62.     {
  63.         $triedScopes = [];
  64.         foreach ($siteAccess->groups as $group) {
  65.             $groupScopeParamName $this->resolveScopeRelativeParamName($paramName$namespace$group->getName());
  66.             if ($this->container->hasParameter($groupScopeParamName)) {
  67.                 return $this->container->getParameter($groupScopeParamName);
  68.             }
  69.             $triedScopes[] = $group->getName();
  70.         }
  71.         throw new ParameterNotFoundException($paramName$namespace$triedScopes);
  72.     }
  73.     protected function getParameterFromResolverForGroup(SiteAccessGroup $siteAccessGroupstring $paramNamestring $namespace)
  74.     {
  75.         $groupScopeParamName $this->resolveScopeRelativeParamName($paramName$namespace$siteAccessGroup->getName());
  76.         if (!$this->container->hasParameter($groupScopeParamName)) {
  77.             throw new ParameterNotFoundException($paramName$namespace, [$siteAccessGroup]);
  78.         }
  79.         return $this->container->getParameter($groupScopeParamName);
  80.     }
  81.     private function isSiteAccessGroupScope($scope): bool
  82.     {
  83.         return array_key_exists($scope$this->siteAccessGroups);
  84.     }
  85. }