|
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\ConfigResolverInterface; |
|
12
|
|
|
use eZ\Publish\Core\MVC\Exception\ParameterNotFoundException; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
15
|
|
|
|
|
16
|
|
|
abstract class ContainerConfigResolver implements ConfigResolverInterface, ContainerAwareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
use ContainerAwareTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
private $scope; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $defaultNamespace; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(string $scope, string $defaultNamespace) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->scope = $scope; |
|
29
|
|
|
$this->defaultNamespace = $defaultNamespace; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getParameter(string $paramName, ?string $namespace = null, ?string $scope = null) |
|
33
|
|
|
{ |
|
34
|
|
|
[$namespace, $scope] = $this->resolveNamespaceAndScope($namespace, $scope); |
|
35
|
|
|
$scopeRelativeParamName = $this->getScopeRelativeParamName($paramName, $namespace, $scope); |
|
36
|
|
|
if ($this->container->hasParameter($scopeRelativeParamName)) { |
|
37
|
|
|
return $this->container->getParameter($scopeRelativeParamName); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
throw new ParameterNotFoundException($paramName, $namespace, [$scope]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function hasParameter(string $paramName, ?string $namespace = null, ?string $scope = null): bool |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->container->hasParameter($this->resolveScopeRelativeParamName($paramName, $namespace, $scope)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDefaultNamespace(): string |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->defaultNamespace; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setDefaultNamespace(string $defaultNamespace): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->defaultNamespace = $defaultNamespace; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function resolveScopeRelativeParamName(string $paramName, string $namespace = null, string $scope = null): string |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->getScopeRelativeParamName($paramName, ...$this->resolveNamespaceAndScope($namespace, $scope)); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function resolveNamespaceAndScope(string $namespace = null, string $scope = null): array |
|
64
|
|
|
{ |
|
65
|
|
|
return [$namespace ?: $this->getDefaultNamespace(), $scope ?? $this->scope]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
private function getScopeRelativeParamName(string $paramName, string $namespace, string $scope): string |
|
69
|
|
|
{ |
|
70
|
|
|
return "$namespace.$scope.$paramName"; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks for function calls that miss required arguments.