Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Nov 13, 2021

Companion PR to symfony/symfony#43181

This adds support for detecting bundle mapping if a bundle is using the newer directory structure.

@malarzm
Copy link
Member

malarzm commented Nov 15, 2021

@mbabker thanks for the PR!

This adds support for detecting bundle mapping if a bundle is using the newer directory structure.

Could you please link what the newer directory structure looks like? I tried googling but to no avail, from the PR I guess that Resources folder is being ditched?

If above is true we have some references in the docs that mapping files should be put in Resources/config/doctrine/ directory (for instance https://www.doctrine-project.org/projects/doctrine-mongodb-bundle/en/4.3/config.html#mapping-configuration). Could you please write some note that it now varies basing on Symfony's version?

@mbabker
Copy link
Contributor Author

mbabker commented Nov 15, 2021

Could you please link what the newer directory structure looks like? I tried googling but to no avail, from the PR I guess that Resources folder is being ditched?

Pretty much the same as a Flex application's structure, see https://symfony.com/doc/current/bundles/best_practices.html#directory-structure

If above is true we have some references in the docs that mapping files should be put in Resources/config/doctrine/ directory (for instance https://www.doctrine-project.org/projects/doctrine-mongodb-bundle/en/4.3/config.html#mapping-configuration). Could you please write some note that it now varies basing on Symfony's version?

It's not entirely Symfony version dependent, it's pretty much 100% bundle dependent. Symfony itself supports the newer root structure since 4.4, but admittedly I haven't seen it used on too many bundles yet (I'm using it on branches I've dropped Symfony 3.4 support because I do think it's a bit cleaner, but that's a subjective opinion at best), and I can't say I've seen anything that implies that the older structure with the Resources folder that everyone knows will be going away anytime soon.

The gist of it though is that for bundles, if you use the structure recommended in the best practices guide, when a combination of the Doctrine Bridge PR and the Doctrine bundle PR(s) (both here and the ORM) relevant to your bundle land, and your minimum versions support these PRs, then you can put your mapping files in config/doctrine and they'd be automatically picked up the same way that they are from Resources/config/doctrine now. If you're crazy enough to live on the edge and use the newer structure AND want to put the files in config/doctrine, you can do it now, but you have to deal with the path registration on your own (see https://github.com/BabDev/MoneyBundle/blob/1.x/src/BabDevMoneyBundle.php for an example).

@malarzm
Copy link
Member

malarzm commented Nov 16, 2021

Thanks for the explanation :) I still think the docs could be updated to reflect that config/doctrine will be automatically picked up if possible (and using one or another is up to user's taste)

$loader->load($config, $container);

$calls = $container->getDefinition('doctrine_mongodb.odm.default_metadata_driver')->getMethodCalls();
$this->assertEquals('doctrine_mongodb.odm.default_xml_metadata_driver', (string) $calls[0][1][0]);
Copy link
Contributor

@franmomu franmomu Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this assert is failing because this will only be true when using Symfony >= 5.4 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'll have to figure out what's happening differently here compared to DoctrineBundle then because the CI build is green with the same feature PR merged and I didn't add any conditionals to the tests there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm comparing with https://github.com/doctrine/DoctrineBundle/pull/1418/files, there is no testNewBundleStructureXmlBundleMappingDetection test there

@franmomu
Copy link
Contributor

franmomu commented Nov 22, 2021

The failing tests are not related to this PR, I think they will be fixed with #714, can you please add those changes here to have the CI build green? everything else LGTM.

@franmomu
Copy link
Contributor

Restarting the build

@franmomu franmomu closed this Nov 22, 2021
@franmomu franmomu reopened this Nov 22, 2021
@franmomu franmomu requested review from malarzm and IonBazan November 22, 2021 10:24
@IonBazan IonBazan added this to the 4.4.0 milestone Nov 22, 2021
@malarzm malarzm merged commit d4cfb00 into doctrine:4.4.x Nov 22, 2021
@malarzm
Copy link
Member

malarzm commented Nov 22, 2021

Thanks a lot @mbabker!

@mbabker mbabker deleted the new-bundle-structure-support branch November 22, 2021 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants