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