ex3v ex3v - 1 year ago 140
Git Question

Symfony2 - creating own vendor bundle - project and git strategy

We're considering creating our own

bundle for entity mapping and services for use within few separate apps. A bundle should be easy to modify, run, include and test. I know about Best Practices for Structuring Bundles, but I don't know what
strategy to use when it comes to development.

Should we create
bundle as a whole project and commit whole repository to our git server, or is it better to start source control only for root of
bundle and push only its contents? I see this approach in bundles available on
, but I don't know easy and comfortable way to develop bundles that way.

Answer Source

Create a new empty symfony project

php composer.phar create-project symfony/framework-standard-edition demo/ 2.4.1
cd demo

Generate a new bundle

(for example src/Company/DemoBundle)

php app/console generate:bundle
cd src/Company/DemoBundle/

Init your github repository in src/Company/DemoBundle

git init
touch README.md
git add .
git commit -m "initial commit"
git remote add origin https://github.com/YourAccount/DemoBundle.git
git push -u origin master

Add a composer.json file


    "name" : "company/demobundle",
    "description" : "A demo bundle",
    "type" : "symfony-bundle",
    "authors" : [{
        "name" : "demo",
        "email" : "demo@company.com"
    "keywords" : [
        "demo bundle"
    "license" : [
    "require" : {
    "autoload" : {
        "psr-0" : {
            "Company\\DemoBundle" : ""
    "target-dir" : "Company/DemoBundle",
    "repositories" : [{
    "extra" : {
    "branch-alias" : {
            "dev-master" : "some_version-dev"

Now you have the base structure of your bundle

Use it in another project


    "require" : {
        "company/demobundle" : "dev-master"
    "repositories" : [{
        "type" : "vcs",
        "url" : "https://github.com/Company/DemoBundle.git"


curl -sS https://getcomposer.org/installer | php
php composer.phar update company/demobundle


new Company\DemoBundle\CompanyDemoBundle(),

Work on it

  • You can clone your DemoBundle in the src/Company folder, then manually install it
  • You can use symlink


You can develop and test your bundle in your first project and use it with github and composer in your second project.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download