-
-
Notifications
You must be signed in to change notification settings - Fork 454
[WIP] add compiler pass for bundles to register mappings #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This needs support for annotation and staticphp driver types. |
this now follows the new instantiation model with factory methods and adds support for annotation and staticphp drivers. is there a sane way to do testing that will figure out if the drivers actually can be instantiated when defined by the compiler pass? should i add something to the XmlDoctrineExtensionTest ? or do we have something general that can give me the container builder? |
the PR on symfony core is now merged. any inputs on testing? other improvements? or do we merge as-is? |
|
||
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass as BaseMappingPass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't alias it as it is not needed
@dbu While reviewing this PR, I aslo found a design flaw in the base class: https://github.com/symfony/symfony/pull/7599/files#r3858891 thsi should be fixed first IMO as it will probably require adding a constructor argument in the parent class |
thanks for the feedback stof. and sorry for needing so much guidance to do this right :-( anyway, i created symfony/symfony#7755 and pushed a fix for this to this PR. i also adjusted fos user bundle so that we see how things look. |
*/ | ||
public static function createStaticPhpMappingDriver(array $namespaces, array $directories, array $managerParameters = array(), $enabledParameter = false) | ||
{ | ||
$driver = new Definition('Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver', array($directories)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this and the PHPDriver are actually in doctrine commons. i wonder if we could move the factory methods for those into the bridge? it will be copy-paste, except for the actual compiler pass class instantiated. hm. sounds like cludgy code - but if we keep it here, we will copy-paste to mongo/couch/phpcr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the same code will end up existing in multiple bundles, that sounds like a prime candidate for the bridge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem is its not exactly the same, we need to know what to
instantiate. i could add something like
createStaticPhpMappingDriverDefinition to the bridge and keep the new
in the extending classes. or else pass the class as argument and do new $class
if this is not considered bad style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't realize how tiny these methods were. Were you considering moving all of these to the bridge, or just createStaticPhpMappingDriver()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
staticphpdriver and phpdriver are the same classes for all doctrines. the rest is specific anyways. but yeah i guess they are so small that its not worth it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is worth moving it to the bridge for a single line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, agree. i will copy it to the compiler passes of mongo/couch/phpcr then.
the doc PR already got merged - can you please merge or tell me what is missing? symfony/symfony-docs#2507 |
[WIP] add compiler pass for bundles to register mappings
i noticed that i use the SymfonyFileLocator exclusively. this prevents using mapping files that have the full name including the namespace, for example to map a super class of the class a bundle provides. should i add another parameter to the factory methods to allow to override the locator class or a boolean to tell if it should be default file locator or symfony file locator? or do we just document how to do create a custom definition and call the constructor of the compiler pass directly? |
Possible, that this (currently?) doesn't work with the console? |
it should work on console. actually i mainly tested this with the FOSUserBundle creating users on the console. |
I should gave been a little bit more concrete I guess 😉 |
yeah it will look in Entities, but those are just mapped superclasses that point to the model. it should work regardless of whether you extend the Entities or Model classes. |
@dbu I did not just extend a model-class, I use them. I moved all my entity-classes (wasn't that much in my experimental app 😉 ) to The application itself works fine, but the console command I mentioned not. |
that is not related to this, right? FriendsOfSymfony/FOSUserBundle#1137 to get both mappings, you also need to register the compiler pass for each database. see FriendsOfSymfony/FOSUserBundle#1081 - FOSUserBundle only ever has one database active at a time, but if you have your own things, there should be no problem having more than one compiler pass actually active. |
I currently only use one database (because of this issue 😉 ), so this shouldn't be a problem. Also the application itself works fine so far, but not doctrines own command line tool. I've called It seems, that it is completey irrelevant, what is in this file. Also I have no idea how to disable this behaviour for single bundles. |
ah, if you still have an Entity folder you must put your mappings in a |
This PR was squashed before being merged into the master branch (closes symfony#7599). Discussion ---------- [Doctrine-Bridge] add a base compiler pass class to register doctrine mappings | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | not on code, but defining best practices | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#2507 Reusable bundles providing model classes should not rely on the automapping provided by the doctrine bundles. What is more, the same model can often be mapped to Doctrine ORM, MongoODM, CouchODM and PHPCR-ODM. This pull request adds a base class for a compiler pass that the concrete doctrine bundles extend to provide a default compiler pass that makes it trivial for bundles to register their mappings. See doctrine/DoctrineBundle#177 The FOSUserBundle shows how this would look in practice. See FriendsOfSymfony/FOSUserBundle#1081 I will create the documentation pull request as well as pull requests for the mongo, couch and phpcr bundles once we agree how exactly to do this. Commits ------- 099fd9f [Doctrine-Bridge] add a base compiler pass class to register doctrine mappings
use the compiler pass added to the doctrine bridge to provide a nice compiler pass for bundles. See symfony/symfony#7599
i will also write documentation once we agree on the exact format. for now see FriendsOfSymfony/FOSUserBundle#1081 for an example how this is intended to be used.