1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* (c) Yaroslav Honcharuk <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Yarhon\RouteGuardBundle\DependencyInjection\Container; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; |
16
|
|
|
use Symfony\Component\Config\Definition\Processor; |
17
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception as ConfigDefinitionException; |
18
|
|
|
use Yarhon\RouteGuardBundle\Exception\LogicException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ForeignExtensionAccessor |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Processor |
27
|
|
|
*/ |
28
|
|
|
private $processor; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Processor|null $processor |
32
|
|
|
*/ |
33
|
4 |
|
public function __construct(Processor $processor = null) |
34
|
|
|
{ |
35
|
4 |
|
$this->processor = $processor ?: new Processor(); |
36
|
4 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns processed config of a foreign extension outside of it's context. |
40
|
|
|
* |
41
|
|
|
* @param ContainerBuilder $container |
42
|
|
|
* @param ExtensionInterface $extension |
43
|
|
|
* |
44
|
|
|
* @return array Processed configuration |
45
|
|
|
* |
46
|
|
|
* @throws LogicException When extension configuration class in not an instance of ConfigurationExtensionInterface |
47
|
|
|
*/ |
48
|
4 |
|
public function getProcessedConfig(ContainerBuilder $container, ExtensionInterface $extension) |
49
|
|
|
{ |
50
|
4 |
|
if (!($extension instanceof ConfigurationExtensionInterface)) { |
51
|
1 |
|
throw new LogicException(sprintf('"%s" extension class is not an instance of %s.', |
52
|
1 |
|
$extension->getAlias(), ConfigurationExtensionInterface::class)); |
53
|
|
|
} |
54
|
|
|
|
55
|
3 |
|
$configuration = $extension->getConfiguration([], $container); |
56
|
3 |
|
$configs = $container->getExtensionConfig($extension->getAlias()); |
57
|
|
|
|
58
|
|
|
try { |
59
|
3 |
|
$processed = $this->processor->processConfiguration($configuration, $configs); |
|
|
|
|
60
|
1 |
|
} catch (ConfigDefinitionException $e) { |
61
|
1 |
|
throw new LogicException(sprintf('Cannot read configuration of the "%s" extension because of configuration exception.', $extension->getAlias()), 0, $e); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
return $processed; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|