Sometimes there are some functions or procedures that I write as helpers and utilities to use all across my apps... Now I'm starting to use Symfony 2, and I don't know what is the best way according to symfony 2 philosophy of Bundles... I wouldn't like to have to create a whole Bundle just to store maybe a couple of functions, but if it is the best way I'll do it. Thanks!
Asked
Active
Viewed 1,627 times
1 Answers
8
If your utilities and helpers are not Symfony specific, create a library in a separate repo and install it to vendors using the deps
with the bin/vendors install
command or via Composer, which will become the default way of managing vendors since Symfony 2.1.
If you want your library to integrate seamlessly with Symfony, create a bundle in another separate repo and install it to vendors. This way your library could be used outside Symfony projects, but provide some conveniences when used in Symfony ones.
Also see a somewhat related question.

Community
- 1
- 1

Elnur Abdurrakhimov
- 44,533
- 10
- 148
- 133
-
So, I should make a bundle anyway, but I should install it in the vendors folder just like any 3rd party bundles I install in my project? am I right? this new way of structuring projects seems really good, but yet a little complicated... I'm not familiar with Composer at all... Have you some documentation on how to use Composer with symfony? How should I organize the directory structure in this new vendor-side Bundle? Sorry, I'm just starting with symfony 2... thank you very much!!! – Throoze Apr 10 '12 at 07:54
-
1Composer is straightforward. You just need to create a `composer.json` file where you declare dependencies and project info. See [Getting Started](http://getcomposer.org/doc/00-intro.md), [Basic Usage](http://getcomposer.org/doc/01-basic-usage.md) and this [example](https://github.com/noiselabs/SmartyBundle/blob/master/composer.json) (note the dependency on `symfony/framework-bundle`). – noisebleed Apr 10 '12 at 09:22
-
If your bundle is supposed to be reused across several projects, than yes, you install it like any other 3rd party bundle. The best way to learn how to make your bundles is to get some theory from the Symfony docs first and then look at existing bundles to see how they're implemented. And don't bother about Composer until Symfony 2.1 is released. – Elnur Abdurrakhimov Apr 10 '12 at 12:33
-
Just so you know. composer.json is heavily inspired on package.json that Node.js use. So I assume you can learn about it's working by reading about that too. – renoirb Jun 14 '12 at 22:07