8000 Simplify api · symfony/symfony@24180d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 24180d1

Browse files
committed
Simplify api
1 parent 762cf0d commit 24180d1

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/Symfony/Component/HttpKernel/Bundle/SimpleBundle.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
namespace Symfony\Component\HttpKernel\Bundle;
1313

14 8000 -
use Symfony\Component\Config\Definition\Builder\NodeParentInterface;
1514
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1615
use Symfony\Component\Config\Definition\ConfigurationInterface;
1716
use Symfony\Component\DependencyInjection\ContainerBuilder;
1817
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1918

2019
/**
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}.
2322
*
2423
* @author Guilhem N. <egetick@gmail.com>
2524
*/
@@ -30,9 +29,11 @@ abstract class SimpleBundle extends Bundle implements ConfigurationInterface
3029
*/
3130
final public function getContainerExtension()
3231
{
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;
3637
}
3738

3839
/**
@@ -41,14 +42,14 @@ final public function getContainerExtension()
4142
final public function getConfigTreeBuilder()
4243
{
4344
$treeBuilder = new TreeBuilder();
44-
$rootNode = $treeBuilder->root($this->getAlias());
45+
$rootNode = $treeBuilder->root($this->getContainerExtension()->getAlias());
4546

4647
$this->buildConfiguration($rootNode);
4748

4849
return $treeBuilder;
4950
}
5051

51-
protected function buildConfiguration(NodeParentInterface $rootNode)
52+
protected function buildConfiguration(TreeBuilder $rootNode)
5253
{
5354
}
5455

@@ -58,19 +59,28 @@ protected function buildContainer(array $config, ContainerBuilder $container)
5859
}
5960

6061
/**
61-
* Simple {@link ExtensionInterface} supporting {@link MicroBundle}.
62+
* Simple {@link Extension} supporting {@link SimpleBundle}.
6263
*
6364
* @internal
6465
*/
6566
final class SimpleExtension extends Extension
6667
{
6768
private $bundle;
68-
private $buildContainer;
6969

70-
public function __construct(SimpleBundle $bundle, Closure $buildContainer)
70+
public function __construct(SimpleBundle $bundle)
7171
{
7272
$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);
7484
}
7585

7686
/**
@@ -80,7 +90,9 @@ public function load(array $configs, ContainerBuilder $container)
8090
{
8191
$config = $this->processConfiguration($this->bundle, $configs);
8292

83-
$f = $this->buildContainer;
93+
$f = Closure::bind(function (array $config, ContainerBuilder $container) {
94+
$this->buildContainer($config, $container);
95+
}, $bundle, SimpleBundle::class);
8496
$f($config, $container);
8597
}
8698

0 commit comments

Comments
 (0)
0