Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you organize your bundles in Symfony2 projects? [closed]

I have the exact question that this guy has: http://groups.google.com/group/symfony2/browse_thread/thread/cd35132cc6972f29

I'll just copy-paste it here:

I was wondering what different ways of organizing bundles within a project people are using.

I seem to end up with either one massive bundle for a project or a lot of bundles which are closely related (dependant) to each other. eg;

I implemented my own user entity and login forms etc, but the users are linked to an organization (with some functionality). Etc ... It's mostly the entities that overlap a lot I guess ...

Do you guys split them up or dump them all in the same bundle?

like image 773
Ohas Avatar asked Dec 07 '11 13:12

Ohas


People also ask

What are bundles Symfony?

A Symfony bundle is a collection of files and folders organized in a specific structure. The bundles are modeled in such a way that it can be reused in multiple applications. The main application itself is packaged as a bundle and it is generally called AppBundle.

What is PHP bundle?

A bundle can be considered essentially a plugin for a Symfony project; it can wrap any functionality found in a Symfony application including configuration, controllers, routes, services, event listeners, templates, etc.


2 Answers

Edit: I don't use bundles for app-specific code anymore.


Personally I prefer to have a bundle per a section of an application. For example:

  • UserBundle
  • BlogBundle
  • ForumBundle
  • JobBundle
  • StoreBundle
  • etc

This is okay if the app is a mishmash of several functionalities, none of which is big enough to require a separate application and/or a subdomain. But if I was developing a big webstore applicaton, my bundles would be more specific:

  • UserBundle
  • ProductBundle
  • CartBundle
  • SearchBundle
  • WishlistBundle
  • etc

So, I'd say, it depends on the focus of the project. What's just a section for one project could be the core functionality of another.

And I usually have CommonBundle, where all the common stuff goes, like global CSS, images, layouts, etc.

Also there are at least two options for the backend organization:

  1. each bundle has its own backend section, or
  2. there is one big backend bundle.

Personally I lean towards the first option and you can read about it in my previous answer, but there are people who prefer to have a separate bundle for the whole backend — probably using one of the admin bundles.

By the way, it's perfectly okay for bundles to be interconnected — you don't have to make them all independent of each other. For example, JMSDiExtraBundle depends on the metadata library and JMSAopBundle, which in turn depends on cg-library. If you'll try to keep bundles totally independent, you'll end up with big monolithic one-bundle lumps of code.

like image 116
Elnur Abdurrakhimov Avatar answered Oct 20 '22 21:10

Elnur Abdurrakhimov


For every project I start off with one CoreBundle, where I put everything together. Then I just develop features in it and as time goes I reevaluate it - if I might use this feature somewhere else someday (or even release to open source), I move it to a new bundle.

"Size" of the feature worth separate bundle doesn't really matter - I've seen OS bundles as big as a 1 single js file :D

One thing for sure - stuffing everything in a single bundle is bad, it goes against the whole reason why this architecture was implemented in the first place!

like image 37
Inoryy Avatar answered Oct 20 '22 19:10

Inoryy