|
14 | 14 | use Symfony\Component\Config\Definition\Builder\NodeParentInterface;
|
15 | 15 | use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
16 | 16 | use Symfony\Component\Config\Definition\ConfigurationInterface;
|
17 |
| -use Symfony\Component\Config\Definition\Processor; |
18 |
| -use Symfony\Component\DependencyInjection\Container; |
19 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
20 |
| -use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; |
21 |
| -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
| 18 | +use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
22 | 19 |
|
23 | 20 | /**
|
24 | 21 | * A all-in-one implementation of {@link BundleInterface},
|
25 | 22 | * {@link ExtensionInterface} and {@link ConfigurationInterface}.
|
26 | 23 | *
|
27 | 24 | * @author Guilhem N. <egetick@gmail.com>
|
28 | 25 | */
|
29 |
| -abstract class MicroBundle extends Bundle implements ExtensionInterface, ConfigurationExtensionInterface, ConfigurationInterface |
| 26 | +abstract class SimpleBundle extends Bundle implements ConfigurationInterface |
30 | 27 | {
|
31 | 28 | /**
|
32 | 29 | * {@inheritdoc}
|
33 | 30 | */
|
34 | 31 | final public function getContainerExtension()
|
35 | 32 | {
|
36 |
| - return $this; |
| 33 | + return new SimpleExtension($this, function (array $config, ContainerBuilder $container) { |
| 34 | + $this->buildContainer($config, $container); |
| 35 | + }); |
37 | 36 | }
|
38 | 37 |
|
39 | 38 | /**
|
40 | 39 | * {@inheritdoc}
|
41 | 40 | */
|
42 |
| - public function getXsdValidationBasePath() |
| 41 | + final public function getConfigTreeBuilder() |
43 | 42 | {
|
44 |
| - return false; |
| 43 | + $treeBuilder = new TreeBuilder(); |
| 44 | + $rootNode = $treeBuilder->root($this->getAlias()); |
| 45 | + |
| 46 | + $this->buildConfiguration($rootNode); |
| 47 | + |
| 48 | + return $treeBuilder; |
45 | 49 | }
|
46 | 50 |
|
47 |
| - /** |
48 |
| - * {@inheritdoc} |
49 |
| - */ |
50 |
| - public function getNamespace() |
| 51 | + protected function buildConfiguration(NodeParentInterface $rootNode) |
51 | 52 | {
|
52 |
| - return 'http://example.org/schema/dic/'.$this->getAlias(); |
53 | 53 | }
|
54 | 54 |
|
55 |
| - /** |
56 |
| - * {@inheritdoc} |
57 |
| - */ |
58 |
| - public function getAlias() |
| 55 | + protected function buildContainer(array $config, ContainerBuilder $container) |
59 | 56 | {
|
60 |
| - // check naming convention |
61 |
| - $basename = preg_replace('/Bundle$/', '', $this->getName()); |
62 |
| - |
63 |
| - return Container::underscore($basename); |
64 | 57 | }
|
| 58 | +} |
65 | 59 |
|
66 |
| - /** |
67 |
| - * {@inheritdoc} |
68 |
| - */ |
69 |
| - final public function load(array $configs, ContainerBuilder $container) |
70 |
| - { |
71 |
| - $processor = new Processor(); |
72 |
| - $config = $processor->processConfiguration($this, $configs); |
| 60 | +/** |
| 61 | + * Simple {@link ExtensionInterface} supporting {@link MicroBundle}. |
| 62 | + * |
| 63 | + * @internal |
| 64 | + */ |
| 65 | +final class SimpleExtension extends Extension |
| 66 | +{ |
| 67 | + private $bundle; |
| 68 | + private $buildContainer; |
73 | 69 |
|
74 |
| - $this->buildContainer($config, $container); |
| 70 | + public function __construct(SimpleBundle $bundle, Closure $buildContainer) |
| 71 | + { |
| 72 | + $this->bundle = $bundle; |
| 73 | + $this->buildContainer = $buildContainer; |
75 | 74 | }
|
76 | 75 |
|
77 | 76 | /**
|
78 | 77 | * {@inheritdoc}
|
79 | 78 | */
|
80 |
| - final public function getConfiguration(array $config, ContainerBuilder $container) |
| 79 | + public function load(array $configs, ContainerBuilder $container) |
81 | 80 | {
|
82 |
| - return $this; |
| 81 | + $config = $this->processConfiguration($this->bundle, $configs); |
| 82 | + |
| 83 | + $f = $this->buildContainer; |
| 84 | + $f($config, $container); |
83 | 85 | }
|
84 | 86 |
|
85 | 87 | /**
|
86 | 88 | * {@inheritdoc}
|
87 | 89 | */
|
88 |
| - final public function getConfigTreeBuilder() |
89 |
| - { |
90 |
| - $treeBuilder = new TreeBuilder(); |
91 |
| - $rootNode = $treeBuilder->root($this->getAlias()); |
92 |
| - |
93 |
| - $this->buildConfiguration($rootNode); |
94 |
| - |
95 |
| - return $treeBuilder; |
96 |
| - } |
97 |
| - |
98 |
| - protected function buildConfiguration(NodeParentInterface $rootNode) |
99 |
| - { |
100 |
| - } |
101 |
| - |
102 |
| - protected function buildContainer(array $config, ContainerBuilder $container) |
| 90 | + public function getConfiguration(array $config, ContainerBuilder $container) |
103 | 91 | {
|
| 92 | + return $this->bundle; |
104 | 93 | }
|
105 | 94 | }
|
0 commit comments