Oh i forgot a point:

If we have explicit definitions of the bundles you could also make it implicit 
again in your own bundles (or in shipped bundles)
inside an extension.

This is what "not so obvious drawbacks" (1) describes. You wouldnt have to 
specify the ORM => Bundle dependency in the config.yml
but could just go about and attach it to an ORM/ODM via an extension. We could 
write some Helper code so that people can
do that in a one-liner in their own extensions.

On Wed, 8 Dec 2010 23:08:26 +0100
Benjamin Eberlei <[email protected]> wrote:

> Hello everyone,
> 
> We discussed the Mapping configuration of the Doctrine bundles in our last 
> IRC meeting and I had the time to investigate possible changes tonight. 
> @Fabien: I know you want the autodetection in to simplify usage for starters, 
> but there are very real drawbacks about it. I present the problems and a very 
> good solution (that will not even complicate usage for starters).
> 
> First about the auto-detection assumptions:
> 
> 1. If any *.xml file exists in Resources/config/doctrine/orm/ use the 
> XmlDriver and register it exclusively for classes $BundleName/Entities.
> 2. Else If any *.yml file exists in Resources/config/doctrine/orm/ use the 
> YamlDriver and register it exclusively for classes $BundleName/Entities.
> 3. If no xml or yml is found assume the user meant Annotations and register 
> it $bundleName/Entities given that directory exists.
> 
> Obvious drawbacks:
> 
> 1. You HAVE to have your entities in $BundleName/Entities for Annotations
> 2. Even if you define xml and yml to have entities elsewhere in your 
> resources, they won't be found, since the mapping driver only matches for 
> $BundleName/Entities
> 3. You cannot define any other Mapping Driver (PHP or StaticPHP for example)
> 4. Taking MongoDB Bundle into the loop. You have to think of absurd Model/* 
> Entity/* Document/* Inheritance hierachies to be able to re-use code. (See 
> Doctrine User Bundle)
> 
> Not so obvious drawbacks:
> 
> 1. If you were to snoop around Doctrine Bundles auto detection in your own 
> extension and do something like:
> 
> $mapDef = $container->getDefinition('doctrine.orm.metadata_driver');
> $mapDef->addMethodCall('addDriver', array(new Reference('my_driver'), 
> 'MyBundle\Entities');
> 
> It wouldnt work! Why? The DriverChain already added an annotations driver for 
> MyBundle\Entities. So the choice here would be to rename the folder to 
> something not Entities. So you can only configure it on your own if you don't 
> follow Symfony2 naming standards.
> 
> 2. Currently all metadata drivers are added to all entity managers. This is 
> necessary, because at the moment of Doctrine Bundle Boot, there is no way to 
> know which bundle is used with which entity manager configuration. Of course 
> you could say this is for the user to figure out. But it will lead to ALL SQL 
> to be executed against every Entity Manager all the time when using 
> SchemaTool. Even for the entities you don't use with that Entity Manager.
> 
> 3. Bundles that have both ORM and ODM configurations get registered in both 
> ORM and ODM because of auto-detection. So if i use the MongoDB User Bundle, i 
> still get Schema Tool suggesting me to add the UserBundle SQL tables.
> 
> Solution:
> 
> 1. Be explicit! At the minimum you have to configure which bundle uses which 
> ORM/ODM. See a cascading example of the possible configuration complexities:
> 
> doctrine.orm:
>     default:
>         bundles:
>             bundleName1: ~
>             bundleName2: yml
>             bundleName3: { type: annotation, dir: Entities/ }
>             bundleName4: { type: xml, dir: Resources/config/doctrine/mapping }
>             bundleName5: { type: yml, dir: doctrine/metadata }
>           bundleName6:
>                 type: yml
>                 dir: [bundle-mappings1/, bundle-mappings2/]
>             bundleName7:
>                 type: my-driver-service
> 
> So when shipping the sandbox or defining a new project, the default bundle 
> should always be enabled for the ORM/ODM to kickstart users:
> 
> doctrine.orm:
>     default:
>         bundles:
>             Hello: ~
> 
> #doctrine.odm:
> #    default:
> #        bundles:
> #            Hello: ~
> 
> 2. Don't register the DriverChain for catching entities at 
> "MyBundle\Entities" but at "MyBundle\" already.
> 
> What do you think?
> 
> greetings,
> Benjamin
> 
> -- 
> If you want to report a vulnerability issue on symfony, please send it to 
> security at symfony-project.com
> 
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
> 

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to