10000 Merge remote branch 'stof/doctrine_simplify' · jaimesuez/symfony@363c3f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 363c3f3

Browse files
committed
Merge remote branch 'stof/doctrine_simplify'
* stof/doctrine_simplify: Removed the short syntax in DoctrineBundle [DoctrineAbstractBundle] Removed obsolete code as the normalization is now done by the Configuration classes [DoctrineMongoDBBundle] Removed the short syntax for the configuration
2 parents 129d7c7 + 4dd45d3 commit 363c3f3

21 files changed

+198
-289
lines changed

src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,7 @@ abstract class AbstractDoctrineExtension extends Extension
4343
protected function loadMappingInformation(array $objectManager, $container)
4444
{
4545
if (isset($objectManager['mappings'])) {
46-
// fix inconsistency between yaml and xml naming
47-
if (isset($objectManager['mappings']['mapping'])) {
48-
if (isset($objectManager['mappings']['mapping'][0])) {
49-
$objectManager['mappings'] = $objectManager['mappings']['mapping'];
50-
} else {
51-
$objectManager['mappings'] = array($objectManager['mappings']['mapping']);
52-
}
53-
}
54-
5546
foreach ($objectManager['mappings'] as $mappingName => $mappingConfig) {
56-
if (is_string($mappingConfig)) {
57-
$mappingConfig = array('type' => $mappingConfig);
58-
}
5947
if (!isset($mappingConfig['dir'])) {
6048
$mappingConfig['dir'] = false;
6149
}
@@ -75,12 +63,6 @@ protected function loadMappingInformation(array $objectManager, $container)
7563
$mappingConfig['is_bundle'] = !file_exists($mappingConfig['dir']);
7664
}
7765

78-
if (isset($mappingConfig['name'])) {
79-
$mappingName = $mappingConfig['name'];
80-
} else if ($mappingConfig === null) {
81-
$mappingConfig = array();
82-
}
83-
8466
if ($mappingConfig['is_bundle']) {
8567
$bundle = null;
8668
foreach ($container->getParameter('kernel.bundles') as $name => $class) {

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

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,8 @@ private function addDbalSection(NodeBuilder $node)
5151
->arrayNode('dbal')
5252
->beforeNormalization()
5353
->ifNull()
54-
->then(function($v) { return array (); }) // Let use the default values with the subsequent closure.
55-
->end()
56-
->beforeNormalization()
57-
->ifTrue(function($v){ return is_array($v) && !array_key_exists('connections', $v) && !array_key_exists('connection', $v); })
58-
->then(function($v) {
59-
$connection = array ();
60-
$keys = array ('dbname', 'host', 'port', 'user', 'password', 'driver', 'driver_class', 'options', 'path', 'memory', 'unix_socket', 'wrapper_class', 'platform_service', 'charset', 'logging');
61-
foreach ($keys as $key) {
62-
if (array_key_exists($key, $v)) {
63-
$connection[$key] = $v[$key];
64-
unset($v[$key]);
65-
}
66-
}
67-
$defaultConnection = isset($v['default_connection']) ? (string) $v['default_connection'] : 'default';
68-
$v['connections'] = array ($defaultConnection => $connection);
69-
$v['default_connection'] = $defaultConnection;
70-
return $v;
71-
})
54+
// Define a default connection using the default values
55+
->then(function($v) { return array ('default_connection' => 'default', 'connections' => array('default' => array())); })
7256
->end()
7357
->scalarNode('default_connection')->isRequired()->cannotBeEmpty()->end()
7458
->fixXmlConfig('type')
@@ -125,23 +109,6 @@ private function addOrmSection(NodeBuilder $node)
125109
{
126110
$node
127111
->arrayNode('orm')
128-
->beforeNormalization()
129-
->ifTrue(function($v){ return is_array($v) && !array_key_exists('entity_managers', $v) && !array_key_exists('entity_manager', $v); })
130-
->then(function($v) {
131-
$entityManager = array ();
132-
$keys = array ('result_cache_driver', 'result-cache-driver', 'metadata_cache_driver', 'metadata-cache-driver', 'query_cache_driver', 'query-cache-driver', 'mappings', 'mapping', 'connection');
133-
foreach ($keys as $key) {
134-
if (array_key_exists($key, $v)) {
135-
$entityManager[$key] = $v[$key];
136-
unset($v[$key]);
137-
}
138-
}
139-
$defaultEntityManager = isset($v['default_entity_manager']) ? (string) $v[& E377 #39;default_entity_manager'] : 'default';
140-
$v['entity_managers'] = array ($defaultEntityManager => $entityManager);
141-
$v['default_entity_manager'] = $defaultEntityManager;
142-
return $v;
143-
})
144-
->end()
145112
->scalarNode('default_entity_manager')->isRequired()->cannotBeEmpty()->end()
146113
->booleanNode('auto_generate_proxy_classes')->defaultFalse()->end()
147114
->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end()

src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testDbalLoad()
4040
$container = $this->getContainer();
4141
$loader = new DoctrineExtension();
4242

43-
$loader->load(array(array('dbal' => array('password' => 'foo')), array(), array('dbal' => array('default_connection' => 'foo')), array()), $container);
43+
$loader->load(array(array('dbal' => array('connections' => array('default'=> array('password' => 'foo')))), array(), array('dbal' => array('default_connection' => 'foo')), array()), $container);
4444

4545
$arguments = $container->getDefinition('doctrine.dbal.default_connection')->getArguments();
4646
$config = $arguments[0];
@@ -112,7 +112,7 @@ public function testDependencyInjectionConfigurationDefaults()
112112
$container = $this->getContainer();
113113
$loader = new DoctrineExtension();
114114

115-
$loader->load(array(array('dbal' => array(), 'orm' => array('mappings' => array('YamlBundle' => array())))), $container);
115+
$loader->load(array(array('dbal' => null, 'orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container);
116116

117117
$this->assertFalse($container->getParameter('doctrine.orm.auto_generate_proxy_classes'));
118118
$this->assertEquals('Doctrine\ORM\Configuration', $container->getParameter('doctrine.orm.configuration_class'));
@@ -134,11 +134,16 @@ public function testDependencyInjectionConfigurationDefaults()
134134
$config = array(
135135
'proxy_namespace' => 'MyProxies',
136136
'auto_generate_proxy_classes' => true,
137-
'mappings' => array('YamlBundle' => array()),
137+
'default_entity_manager' => 'default',
138+
'entity_managers' => array(
139+
'default' => array(
140+
'mappings' => array('YamlBundle' => array()),
141+
)
142+
)
138143
F438 );
139144

140145
$container = $this->getContainer();
141-
$loader->load(array(array('dbal' => array(), 'orm' => $config)), $container);
146+
$loader->load(array(array('dbal' => null, 'orm' => $config)), $container);
142147

143148
$definition = $container->getDefinition('doctrine.dbal.default_connection');
144149
$this->assertEquals('Doctrine\DBAL\Connection', $definition->getClass());
@@ -186,7 +191,7 @@ public function testSingleEntityManagerConfiguration()
186191
$container = $this->getContainer();
187192
$loader = new DoctrineExtension();
188193

189-
$loader->load(array(array('dbal' => array(), 'orm' => array('mappings' => array('YamlBundle' => array())))), $container);
194+
$loader->load(array(array('dbal' => null, 'orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container);
190195

191196
$definition = $container->getDefinition('doctrine.dbal.default_connection');
192197
$this->assertEquals('Doctrine\DBAL\Connection', $definition->getClass());
@@ -357,7 +362,7 @@ public function testBundleEntityAliases()
357362
$container = $this->getContainer();
358363
$loader = new DoctrineExtension();
359364

360-
$loader->load(array(array('orm' => array('mappings' => array('YamlBundle' => array())))), $container);
365+
$loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container);
361366

362367
$definition = $container->getDefinition('doctrine.orm.default_configuration');
363368
$this->assertDICDefinitionMethodCallOnce($definition, 'setEntityNamespaces',
@@ -370,7 +375,7 @@ public function testOverwriteEntityAliases()
370375
$container = $this->getContainer();
371376
$loader = new DoctrineExtension();
372377

373-
$loader->load(array(array('orm' => array('mappings' => array('YamlBundle' => array('alias' => 'yml'))))), $container);
378+
$loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array('alias' => 'yml'))))))), $container);
374379

375380
$definition = $container->getDefinition('doctrine.orm.default_configuration');
376381
$this->assertDICDefinitionMethodCallOnce($definition, 'setEntityNamespaces',
@@ -383,7 +388,7 @@ public function testYamlBundleMappingDetection()
383388
$container = $this->getContainer('YamlBundle');
384389
$loader = new DoctrineExtension();
385390

386-
$loader->load(array(array('orm' => array('mappings' => array('YamlBundle' => array())))), $container);
391+
$loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container);
387392

388393
$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
389394
$this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', array(
@@ -397,7 +402,7 @@ public function testXmlBundleMappingDetection()
397402
$container = $this->getContainer('XmlBundle');
398403
$loader = new DoctrineExtension();
399404

400-
$loader->load(array(array('orm' => array('mappings' => array('XmlBundle' => array())))), $container);
405+
$loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('XmlBundle' => array())))))), $container);
401406

402407
$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
403408
$this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', array(
@@ -411,7 +416,7 @@ public function testAnnotationsBundleMappingDetection()
411416
$container = $this->getContainer('AnnotationsBundle');
412417
$loader = new DoctrineExtension();
413418

414-
$loader->load(array(array('orm' => array('mappings' => array('AnnotationsBundle' => array())))), $container);
419+
$loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('AnnotationsBundle' => array())))))), $container);
415420

416421
$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
417422
$this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', array(
@@ -426,13 +431,17 @@ public function testOrmMergeConfigs()
426431
$loader = new DoctrineExtension();
427432

428433
$loader->load(array(array('orm' => array(
429-
'auto_generate_proxy_classes' => true,
430-
'mappings' => array('AnnotationsBundle' => array())
431-
)),
434+
'auto_generate_proxy_classes' => true,
435+
'default_entity_manager' => 'default',
436+
'entity_managers' => array(
437+
'default' => array('mappings' => array('AnnotationsBundle' => array()))
438+
))),
432439
array('orm' => array(
433440
'auto_generate_proxy_classes' => false,
434-
'mappings' => array('XmlBundle' => array())
435-
))), $container);
441+
'default_entity_manager' => 'default',
442+
'entity_managers' => array(
443+
'default' => array('mappings' => array('XmlBundle' => array()))
444+
)))), $container);
436445

437446
$definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
438447
$this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', array(
@@ -619,7 +628,7 @@ public function testAnnotationsBundleMappingDetectionWithVendorNamespace()
619628
$container = $this->getContainer('AnnotationsBundle', 'Vendor');
620629
$loader = new DoctrineExtension();
621630

622-
$loader->load(array(array('orm' => array('mappings' => array('AnnotationsBundle' => array())))), $container);
631+
$loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('AnnotationsBundle' => array())))))), $container);
623632

624633
$calls = $container->getDefinition('doctrine.orm.default_metadata_driver')->getMethodCalls();
625634
$this->assertEquals('doctrine.orm.default_annotation_metadata_driver', (string) $calls[0][1][0]);

src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
<config>
1010
<orm
1111
auto-generate-proxy-classes="false"
12-
metadata-cache-driver="apc"
12+
default-entity-manager="default"
1313
>
14-
<mapping name="YamlBundle" />
14+
<entity-manager name="default" metadata-cache-driver="apc">
15+
<mapping name="YamlBundle" />
16+
</entity-manager>
1517
</orm>
1618
</config>
1719
</srv:container>

src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
<config>
1010
<dbal />
11-
<orm>
12-
<metadata-cache-driver type="memcache">
13-
<class>Doctrine\Common\Cache\MemcacheCache</class>
14-
<host>localhost</host>
15-
<port>11211</port>
16-
<instance-class>Memcache</instance-class>
17-
</metadata-cache-driver>
18-
<mapping name="YamlBundle" />
11+
<orm default-entity-manager="default">
12+
<entity-manager name="default">
13+
<metadata-cache-driver type="memcache">
14+
<class>Doctrine\Common\Cache\MemcacheCache</class>
15+
<host>localhost</host>
16+
<port>11211</port>
17+
<instance-class>Memcache</instance-class>
18+
</metadata-cache-driver>
19+
<mapping name="YamlBundle" />
20+
</entity-manager>
1921
</orm>
2022
</config>
2123
</srv:container>

src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
88

99
<config>
10-
<orm>
11-
<mapping name="AnnotationsBundle" />
12-
<mapping name="YamlBundle" dir="Resources/config/doctrine/metadata" alias="yml" />
13-
<mapping name="manual" type="xml" prefix="Fixtures\Bundles\XmlBundle"
14-
dir="%kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata"
15-
alias="TestAlias"
16-
/>
10+
<orm default-entity-manager="default">
11+
<entity-manager name="default">
12+
<mapping name="AnnotationsBundle" />
13+
<mapping name="YamlBundle" dir="Resources/config/doctrine/metadata" alias="yml" />
14+
<mapping name="manual" type="xml" prefix="Fixtures\Bundles\XmlBundle"
15+
dir="%kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata"
16+
alias="TestAlias"
17+
/>
18+
</entity-manager>
1719
</orm>
1820
</config>
1921
</srv:container>
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
doctrine:
22
orm:
33
auto_generate_proxy_classes: false
4-
metadata_cache_driver: apc
5-
mappings:
6-
YamlBundle: ~
4+
default_entity_manager: default
5+
entity_managers:
6+
default:
7+
metadata_cache_driver: apc
8+
mappings:
9+
YamlBundle: ~
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
doctrine:
22
dbal: ~
33
orm:
4-
mappings:
5-
YamlBundle: ~
6-
metadata_cache_driver:
7-
type: memcache
8-
class: Doctrine\Common\Cache\MemcacheCache
9-
host: localhost
10-
port: 11211
11-
instance_class: Memcache
4+
default_entity_manager: default
5+
entity_managers:
6+
default:
7+
mappings:
8+
YamlBundle: ~
9+
metadata_cache_driver:
10+
type: memcache
11+
class: Doctrine\Common\Cache\MemcacheCache
12+
host: localhost
13+
port: 11211
14+
instance_class: Memcache
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
doctrine:
22
orm:
3-
mappings:
4-
AnnotationsBundle: ~
5-
YamlBundle:
6-
dir: Resources/config/doctrine/metadata
7-
alias: yml
8-
manual:
9-
type: xml
10-
prefix: Fixtures\Bundles\XmlBundle
11-
dir: %kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata
12-
alias: TestAlias
3+
default_entity_manager: default
4+
entity_managers:
5+
default:
6+
mappings:
7+
AnnotationsBundle: ~
8+
YamlBundle:
9+
dir: Resources/config/doctrine/metadata
10+
alias: yml
11+
manual:
12+
type: xml
13+
prefix: Fixtures\Bundles\XmlBundle
14+
dir: %kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata
15+
alias: TestAlias

src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function createYamlBundleTestContainer()
6262
'connections' => array(
6363
'default' => array(
6464
'driver' => 'pdo_mysql',
65-
'charset' => 'UTF-8',
65+
'charset' => 'UTF8',
6666
'platform-service' => 'my.platform',
6767
)
6868
),
@@ -71,10 +71,15 @@ public function createYamlBundleTestContainer()
7171
'test' => 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType',
7272
),
7373
), 'orm' => array(
74-
'mappings' => array('YamlBundle' => array(
75-
'type' => 'yml',
76-
'dir' => __DIR__ . "/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm",
77-
'prefix' => 'Fixtures\Bundles\YamlBundle',
74+
'default_entity_manager' => 'default',
75+
'entity_managers' => array (
76+
'default' => array(
77+
'mappings' => array('YamlBundle' => array(
78+
'type' => 'yml',
79+
'dir' => __DIR__ . "/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm",
80+
'prefix' => 'Fixtures\Bundles\YamlBundle',
81+
)
82+
)
7883
)))
7984
)), $container);
8085

0 commit comments

Comments
 (0)
0