8000 [DoctrineBundle] added an auto-mapping option to let Symfony register… · beenalee/symfony@dc85727 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc85727

Browse files
committed
[DoctrineBundle] added an auto-mapping option to let Symfony register all enabled bundle mappings
Most of the time, you just want to register all your bundle mappings. It's a bit tedious to do it by hand, not because of the amount of configuration you need to type, but mainly because you can easily forget to do so (also see symfony#502). So, setting auto_mapping to true allows Symfony to automatically register the mappings it founds in the enabled bundles (default is false). Even if auto_mapping is true, you can still define your mappings to add some more or to override the defaults. This change means that the default configuration that works most of the time for most people is simple: orm: auto_mapping: true
1 parent 32070f5 commit dc85727

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ abstract class AbstractDoctrineExtension extends Extension
4242
*/
4343
protected function loadMappingInformation(array $objectManager, ContainerBuilder $container)
4444
{
45+
if (!$objectManager['mappings'] && $objectManager['auto_mapping']) {
46+
// automatically register bundle mappings
47+
foreach (array_keys($container->getParameter('kernel.bundles')) as $bundle) {
48+
if (!isset($objectManager['mappings'][$bundle])) {
49+
$objectManager['mappings'][$bundle] = null;
50+
}
51+
}
52+
}
53+
4554
foreach ($objectManager['mappings'] as $mappingName => $mappingConfig) {
4655
$mappingConfig = array_replace(array(
4756
'dir' => false,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ private function addOrmSection(ArrayNodeDefinition $node)
156156
->children()
157157
->arrayNode('orm')
158158
->beforeNormalization()
159-
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('entity_managers', $v) && !array_key_exists('entity_manager', $v); })
159+
->ifTrue(function ($v) { return null === $v || (is_array($v) && !array_key_exists('entity_managers', $v) && !array_key_exists('entity_manager', $v)); })
160160
->then(function ($v) {
161+
$v = (array) $v;
161162
$entityManager = array();
162163
foreach (array(
163164
'result_cache_driver', 'result-cache-driver',
164165
'metadata_cache_driver', 'metadata-cache-driver',
165166
'query_cache_driver', 'query-cache-driver',
167+
'auto_mapping', 'auto-mapping',
166168
'mappings', 'mapping',
167169
'connection'
168170
) as $key) {
@@ -206,6 +208,7 @@ private function getOrmEntityManagersNode()
206208
->children()
207209
->scalarNode('connection')->end()
208210
->scalarNode('class_metadata_factory_name')->defaultValue('%doctrine.orm.class_metadata_factory_name%')->end()
211+
->scalarNode('auto_mapping')->defaultFalse()->end()
209212
->end()
210213
->fixXmlConfig('hydrator')
211214
->children()
@@ -217,8 +220,6 @@ private function getOrmEntityManagersNode()
217220
->fixXmlConfig('mapping')
218221
->children()
219222
->arrayNode('mappings')
220-
->isRequired()
221-
->requiresAtLeastOneElement()
222223
->useAttributeAsKey('name')
223224
->prototype('array')
224225
->beforeNormalization()

0 commit comments

Comments
 (0)
0