0

Examples given in Symfony 2 webpage

Namespace                       Bundle Class Name
Acme\Bundle\BlogBundle          AcmeBlogBundle
Acme\Bundle\Social\BlogBundle   AcmeSocialBlogBundle
Acme\BlogBundle                 AcmeBlogBundle

My vendor name is 9 characters large, but I find it redundant to have MyVendorName/ForumBundle and class name MyVendorNameForumBundle.php if it resides already in MyVendorName/ForumBundle directory.

Will it bring me future problems if I just name my primary class ForumBundle supposing I want to share? Obviously, the namespace is still MyVendorName/ForumBundle.

Is that class actually used somewhere or is just a one-time config somewhere?

My main concern is that I don't want to use the large name (eg MyVendorName/MyVendorNameForumBundle::someMethod()) everytime I need to access it.

Maybe this isn't all correct, I am new to Symfony 2.

Thanks

1
  • I wouldn't do that. Symfony also uses convention over configuration and i am not sure if all scripts work properly if you do that. (e.g. console commands) Commented Jan 28, 2015 at 21:31

1 Answer 1

1

First off, I wouldn't imagine the namespace Acme\Bundle\BlogBundle coming from AcmeBlogBundle. Something more appropriate would be Acme\BlogBundle, which would make AcmeBlogBundle. If you did Acme\Bundle\BlogBundle, the class name may actually end up being AcmeBundleBlogBundle.

The vendor name is included in the class to prevent conflicts. What if someone else decided to name their bundle class BlogBundle?

I also can't imagine you ever calling a method that directly belongs in the root class of a Symfony2 bundle.

Generally, Symfony2 will provide you with shortcuts to get to the most common things you need. For example, when you reference a controller in your routing.yml:

AcmeSocialBlogBundle:Default:show

It will actually resolve to

Acme\SocialBlogBundle\Controllers\DefaultController::showAction

My suggestion? Relax. The Symfony2 dev team has addressed this concern with shortcut notation already. Follow the convention that is generated by the php app/console generate:bundle command as a starting point and everything else will fall into place. Here are some valid namespaces:

Acme\Plugins\BlogBundle
Acme\BlogBundle
Acme\ClientName\BlogBundle
sjagr\MyAwesomeBundle <-- See how I made my Github username a vendor name?

My word of warning is that when you try and go against the grain of a framework's recommendations, you'll revisit that decision later with regret. I have done so, and I'm currently rewriting Symfony2 apps that I wish I had taken the time to do right in the first place.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.