symfony / symfony-docs

The Symfony documentation
https://symfony.com/doc
Other
2.17k stars 5.12k forks source link

Bundle Naming #3616

Closed ossinkine closed 9 years ago

ossinkine commented 10 years ago

On https://github.com/symfony/symfony-docs/blob/master/cookbook/bundles/best_practices.rst says that namespace must follow the technical interoperability standard PSR-0. Must namespace follow the standard PSR-4? In particular, is it allowed to use the namespace for bundle MyBlogBundle? E.g. can I place my bundle class in src/MyBlogBundle/MyBlogBundle.php?

wouterj commented 10 years ago

Yes, you can do it wherever you like. :)

We may need to update that article though, by adding the PSR-4 standard information. Thanks for notifying us! (you if have some time, youcan also hit the "edit" button yourself and update the article using PSR-4, that'll be very great!)

xabbuh commented 10 years ago

Is the PSR-4 standard really worth to be mentionend here? I mean it doesn't affect any of the guidelines we describe, does it?

ossinkine commented 10 years ago

@xabbuh PSR-0 allows namespaces like \VendorName\NamespaceName, PSR-4 allows namespaces \NamespaceName. Thus PSR-0 does not allow to create a bundle src/MyBlogBundle/MyBlogBundle.php, only src/MyCompany/MyBlogBundle/MyCompanyBlogBundle.php

ossinkine commented 10 years ago

@WouterJ I'd like to, but my English is very bad for it.

wouterj commented 10 years ago

@xabbuh it doesn't affect the text, however it does change the table with examples.

@ossinkine don't worry about your english. 90% of de doc contributors are bad english speaking non-natives (including myself). We'll help you and after all, we have a very friendly merger (@weaverryan) which will fix all bad english in a PR after the merge :laughing:

But well, now I think about it. Nothing in the article talks about the location of the bundle, only about the namespace and name of a bundle. So it isn't affected by PSR-4. Where did you think we were talking about locations? (if we know that, we can add a tip box saying something like "If your bundle uses PSR-4, the namespace may differ from the actual location of the bundle (e.g. Acme\Bundle\Social\BlogBundle can live in src/BlogBundle).")

ossinkine commented 10 years ago

@WouterJ Yes, I mean that file src/MyBlogBundle/MyBlogBundle.php has a namespace MyBlogBundle and class name MyBlogBundle, is it allowed?

xabbuh commented 10 years ago

@ossinkine Your fully qualified namespace would even with PSR-4 be something like \Me\MyBlogBundle. The only difference actually is the depth of your directory structure under src/.

weaverryan commented 10 years ago

I do think we should mention that you're allowed to follow PSR-0 or PSR-4.

I also think that the example table should be updated to give better examples. Specifically, You should have a vendor namespace then your bundle name. I think examples like Acme\Bundle\BlogBundle and Acme\Bundle\Social\BlogBundle are out of date - sure you can do this, but I don't think we should recommend this deep of a namespace structure for your bundles.

Even the Directory Structure section isn't quite right - we talk about a HelloBundle, but it should be AcmeHelloBundle. Enough time has gone by, that this whole entry needs a re-read with some facelifts.

Thanks!

weaverryan commented 10 years ago

And btw, this entry is about re-usable bundles, not application-specific bundles, so we can really target our information at that audience - see #4250.

Thanks!