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