Skip to content

Commit 00c9539

Browse files
committed
Merge remote branch 'vicb/config_base'
* vicb/config_base: [Config] Add a note about the ConfigurationInterface interface in UPDATE.md [MonologBundle] Make The Configuration class implements the ConfigurationInterface [Config] Introduction of an ConfigurationInterface
2 parents 6d4814c + b592946 commit 00c9539

File tree

26 files changed

+253
-126
lines changed

26 files changed

+253
-126
lines changed

UPDATE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ one. It only discusses changes that need to be done when using the "public"
66
API of the framework. If you "hack" the core, you should probably follow the
77
timeline closely anyway.
88

9+
PR10 to PR11
10+
------------
11+
12+
* Extension configuration classes should now implement the
13+
`Symfony\Component\Config\Definition\ConfigurationInterface` interface. Note that
14+
the BC is kept but implementing this interface in your extensions will allow for
15+
further developments.
16+
917
PR9 to PR10
1018
-----------
1119

src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ public function load(array $configs, ContainerBuilder $container)
9999
*/
100100
static protected function processConfigs(array $configs, $debug, array $bundles)
101101
{
102-
$configuration = new Configuration();
103-
$tree = $configuration->getConfigTree($debug, $bundles);
104-
105102
$processor = new Processor();
106-
return $processor->process($tree, $configs);
103+
$configuration = new Configuration($debug, $bundles);
104+
return $processor->processConfiguration($configuration, $configs);
107105
}
108106

109107
/**

src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\AsseticBundle\DependencyInjection;
1313

1414
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
1516

1617
/**
1718
* This class contains the configuration information for the bundle
@@ -22,24 +23,36 @@
2223
* @author Christophe Coevoet <stof@notk.org>
2324
* @author Kris Wallsmith <kris@symfony.com>
2425
*/
25-
class Configuration
26+
class Configuration implements ConfigurationInterface
2627
{
28+
private $bundles;
29+
private $debug;
30+
2731
/**
28-
* Generates the configuration tree.
32+
* Constructor
2933
*
3034
* @param Boolean $debug Wether to use the debug mode
3135
* @param array $bundles An array of bundle names
32-
*
33-
* @return \Symfony\Component\Config\Definition\ArrayNode The config tree
3436
*/
35-
public function getConfigTree($debug, array $bundles)
37+
public function __construct($debug, array $bundles)
38+
{
39+
$this->debug = (Boolean) $debug;
40+
$this->bundles = $bundles;
41+
}
42+
43+
/**
44+
* Generates the configuration tree builder.
45+
*
46+
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
47+
*/
48+
public function getConfigTreeBuilder()
3649
{
37-
$tree = new TreeBuilder();
50+
$builder = new TreeBuilder();
3851

39-
$tree->root('assetic')
52+
$builder->root('assetic')
4053
->children()
41-
->booleanNode('debug')->defaultValue($debug)->end()
42-
->booleanNode('use_controller')->defaultValue($debug)->end()
54+
->booleanNode('debug')->defaultValue($this->debug)->end()
55+
->booleanNode('use_controller')->defaultValue($this->debug)->end()
4356
->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end()
4457
->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end()
4558
->scalarNode('java')->defaultValue('/usr/bin/java')->end()
@@ -51,7 +64,7 @@ public function getConfigTree($debug, array $bundles)
5164
->fixXmlConfig('bundle')
5265
->children()
5366
->arrayNode('bundles')
54-
->defaultValue($bundles)
67+
->defaultValue($this->bundles)
5568
->requiresAtLeastOneElement()
5669
->beforeNormalization()
5770
->ifTrue(function($v) { return !is_array($v); })
@@ -84,6 +97,6 @@ public function getConfigTree($debug, array $bundles)
8497
->end()
8598
;
8699

87-
return $tree->buildTree();
100+
return $builder;
88101
}
89102
}

src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1515
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16+
use Symfony\Component\Config\Definition\ConfigurationInterface;
1617

1718
/**
1819
* This class contains the configuration information for the bundle
@@ -22,28 +23,34 @@
2223
*
2324
* @author Christophe Coevoet <stof@notk.org>
2425
*/
25-
class Configuration
26+
class Configuration implements ConfigurationInterface
2627
{
27-
private $kernelDebug;
28+
private $debug;
2829

2930
/**
30-
* Generates the configuration tree.
31+
* Constructor
3132
*
32-
* @param Boolean $kernelDebug
33+
* @param Boolean $debug Wether to use the debug mode
34+
*/
35+
public function __construct($debug)
36+
{
37+
$this->debug = (Boolean) $debug;
38+
}
39+
40+
/**
41+
* Generates the configuration tree builder.
3342
*
34-
* @return \Symfony\Component\Config\Definition\ArrayNode The config tree
43+
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
3544
*/
36-
public function getConfigTree($kernelDebug)
45+
public function getConfigTreeBuilder()
3746
{
38-
$this->kernelDebug = (bool) $kernelDebug;
39-
4047
$treeBuilder = new TreeBuilder();
4148
$rootNode = $treeBuilder->root('doctrine');
4249

4350
$this->addDbalSection($rootNode);
4451
$this->addOrmSection($rootNode);
4552

46-
return $treeBuilder->buildTree();
53+
return $treeBuilder;
4754
}
4855

4956
private function addDbalSection(ArrayNodeDefinition $node)
@@ -98,7 +105,7 @@ private function getDbalConnectionsNode()
98105
->scalarNode('unix_socket')->end()
99106
->scalarNode('platform_service')->end()
100107
->scalarNode('charset')->end()
101-
->booleanNode('logging')->defaultValue($this->kernelDebug)->end()
108+
->booleanNode('logging')->defaultValue($this->debug)->end()
102109
->end()
103110
->fixXmlConfig('driver_class', 'driverClass')
104111
->children()

src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class DoctrineExtension extends AbstractDoctrineExtension
3131
{
3232
public function load(array $configs, ContainerBuilder $container)
3333
{
34-
$configuration = new Configuration();
3534
$processor = new Processor();
36-
$config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs);
35+
$configuration = new Configuration($container->getParameter('kernel.debug'));
36+
$config = $processor->processConfiguration($configuration, $configs);
3737

3838
if (!empty($config['dbal'])) {
3939
$this->dbalLoad($config['dbal'], $container);

src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/Configuration.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
namespace Symfony\Bundle\DoctrineMigrationsBundle\DependencyInjection;
44

55
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
67

78
/**
89
* DoctrineMigrationsExtension configuration structure.
910
*
1011
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
1112
*/
12-
class Configuration
13+
class Configuration implements ConfigurationInterface
1314
{
1415
/**
15-
* Generates the configuration tree.
16+
* Generates the configuration tree builder.
1617
*
17-
* @return \Symfony\Component\Config\Definition\ArrayNode The config tree
18+
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
1819
*/
19-
public function getConfigTree()
20+
public function getConfigTreeBuilder()
2021
{
2122
$treeBuilder = new TreeBuilder();
2223
$rootNode = $treeBuilder->root('doctrine_migrations', 'array');
@@ -30,6 +31,6 @@ public function getConfigTree()
3031
->end()
3132
;
3233

33-
return $treeBuilder->buildTree();
34+
return $treeBuilder;
3435
}
3536
}

src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/DoctrineMigrationsExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Symfony\Bundle\DoctrineMigrationsBundle\DependencyInjection;
1313

14-
use Symfony\Component\Config\Definition\Processor;
1514
use Symfony\Component\DependencyInjection\ContainerBuilder;
1615
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
16+
use Symfony\Component\Config\Definition\Processor;
1717

1818
/**
1919
* DoctrineMigrationsExtension.
@@ -33,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container)
3333
$processor = new Processor();
3434
$configuration = new Configuration();
3535

36-
$config = $processor->process($configuration->getConfigTree(), $configs);
36+
$config = $processor->processConfiguration($configuration, $configs);
3737

3838
foreach ($config as $key => $value) {
3939
$container->setParameter($this->getAlias().'.'.$key, $value);

src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
66
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7+
use Symfony\Component\Config\Definition\ConfigurationInterface;
78

89
/**
910
* FrameworkExtension configuration structure.
1011
*
1112
* @author Ryan Weaver <ryan@thatsquality.com>
1213
*/
13-
class Configuration
14+
class Configuration implements ConfigurationInterface
1415
{
1516
private $debug;
1617

@@ -25,11 +26,11 @@ public function __construct($debug)
2526
}
2627

2728
/**
28-
* Generates the configuration tree.
29+
* Generates the configuration tree builder.
2930
*
30-
* @return \Symfony\Component\Config\Definition\ArrayNode The config tree
31+
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
3132
*/
32-
public function getConfigTree()
33+
public function getConfigTreeBuilder()
3334
{
3435
$treeBuilder = new TreeBuilder();
3536
$rootNode = $treeBuilder->root('doctrine_mongo_db');
@@ -49,7 +50,7 @@ public function getConfigTree()
4950
->end()
5051
;
5152

52-
return $treeBuilder->buildTree();
53+
return $treeBuilder;
5354
}
5455

5556
/**

src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\DependencyInjection\Definition;
1919
use Symfony\Component\Config\FileLocator;
20-
use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension;
2120
use Symfony\Component\Config\Definition\Processor;
21+
use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension;
2222

2323
/**
2424
* Doctrine MongoDB ODM extension.
@@ -40,7 +40,7 @@ public function load(array $configs, ContainerBuilder $container)
4040

4141
$processor = new Processor();
4242
$configuration = new Configuration($container->getParameter('kernel.debug'));
43-
$config = $processor->process($configuration->getConfigTree(), $configs);
43+
$config = $processor->processConfiguration($configuration, $configs);
4444

4545
// can't currently default this correctly in Configuration
4646
if (!isset($config['metadata_cache_driver'])) {

src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Configuration;
1616
use Symfony\Component\Yaml\Yaml;
17-
1817
use Symfony\Component\Config\Definition\Processor;
1918

2019
class ConfigurationTest extends \PHPUnit_Framework_TestCase
@@ -23,7 +22,7 @@ public function testDefaults()
2322
{
2423
$processor = new Processor();
2524
$configuration = new Configuration(false);
26-
$options = $processor->process($configuration->getConfigTree(), array());
25+
$options = $processor->processConfiguration($configuration, array());
2726

2827
$defaults = array(
2928
'auto_generate_hydrator_classes' => false,
@@ -56,7 +55,7 @@ public function testFullConfiguration($config)
5655
{
5756
$processor = new Processor();
5857
$configuration = new Configuration(false);
59-
$options = $processor->process($configuration->getConfigTree(), array($config));
58+
$options = $processor->processConfiguration($configuration, array($config));
6059

6160
$expected = array(
6261
'proxy_namespace' => 'Test_Proxies',
@@ -141,7 +140,7 @@ public function testMergeOptions(array $configs, array $correctValues)
141140
{
142141
$processor = new Processor();
143142
$configuration = new Configuration(false);
144-
$options = $processor->process($configuration->getConfigTree(), $configs);
143+
$options = $processor->processConfiguration($configuration, $configs);
145144

146145
foreach ($correctValues as $key => $correctVal)
147146
{
@@ -230,7 +229,7 @@ public function testNormalizeOptions(array $config, $targetKey, array $normalize
230229
{
231230
$processor = new Processor();
232231
$configuration = new Configuration(false);
233-
$options = $processor->process($configuration->getConfigTree(), array($config));
232+
$options = $processor->processConfiguration($configuration, array($config));
234233
$this->assertSame($normalized, $options[$targetKey]);
235234
}
236235

0 commit comments

Comments
 (0)