More intuitive matching of bundle directory lookups for Doctrine extensions#309
More intuitive matching of bundle directory lookups for Doctrine extensions#309jmikola wants to merge 1 commit intofabpot:masterfrom jmikola:findBundleDirForNamespace
Conversation
…rom vendor-organized bundles Bundle best practices advocate organizing a bundle under a vendor namespace (e.g. "Bundle\Vendor\VendorBundle"). That puts the onus on the application developer to explicitly add "Bundle\Vendor" to the kernel's bundle directory configuration. Alternatively, when trying to find a directory for a bundle's namespace we can exhaustively check if parent namespaces are defined in the kernel configuration, which this patch implements.
|
Can you give an example of what it simplifies/solves? |
|
The bundle best practices suggest sub-directories for the vendor and category of the bundle. The FOS UserBundle employs this; however, the Doctrine extensions would require the specific vendor/category directory to be defined in the kernel's I think it's a bit much to require the user to register each vendor/category directory in |
|
I am not sure this should be in the DI extension, instead if should be in your Kernel. You can write some code to easily dynamically add all the directories. I think it is better to have less code in Symfony2 for us to maintain and to be more explicit in the configuration side. |
|
If my own bundle needed such a thing, I'd still do it right in the extension. Otherwise, the best solution is just to make in clear in the documentation that any directory path holding a bundle (be it I wouldn't encourage anyone to use your snippet above, though. Adding all sub-directories like that will help bundles that are grouped by only a vendor path. It does nothing for categorized, vendor-grouped bundles, and will likely create garbage paths for non-vendor-named bundles (e.g. |
|
This patch sort of conflicts with pull request 264, i can integrate parts of it but automatic matching will be deprecated in favor of an explicit approach anyways as discussed in the Symfony IRC meeting 3 weeks ago. I can do more work on it this week and finalize it. |
|
yeah ... 264 seems to be the way to do things down the road. |
|
I wish I had seen 264 before doing this :) I agree that it's a better approach; closing this one. |
See commit message. This solves a problem that the FOS\UserBundle had with the Doctrine extensions loading their mapping files, due to the "FOS" vendor segment in their namespace/directory path.
I believe this is an intuitive solution for the application developer, as it removes the necessity to define each vendor explicitly in the kernel's registerBundleDirs() method.
I'm not sure if FrameworkBundle or others have similar problems looking up directors for vendor-organized bundles, but perhaps this code could be useful outside of just the Doctrine extensions.