How to install your own bundle with Composer in Symfony 2.1?

11,016

Solution 1

I've found the answer.

// my_project/compose.json:
{
    "repositories": [
        {
            "type": "vcs",
            "url": "own_repository_url"
        }
    ],

    // ...

    "require": {
        // ...
        "own/bundle": "dev-master"
    }
},

 

// own_repository/own_bundle/compose.json:
{
    "name": "own/bundle"
}

Solution 2

Add a composer.json file to your bundle. For example I have this for one of my bundles:

{
    "name":        "cg/kint-bundle",
    "type":        "symfony-bundle",
    "description": "This bundle lets you use the Kint function in your Twig templates. Kint is a print_r() replacement which produces a structured, collapsible and escaped output",
    "keywords":    ["kint", "debug", "symfony", "bundle", "twig"],
    "homepage":    "http://github.com/barelon/CgKintBundle",
    "license":     "MIT",

    "authors": [
        {
            "name": "Carlos Granados",
            "homepage": "http://github.com/barelon"
        },
        {
            "name": "Symfony Community",
            "homepage": "http://github.com/barelon/CgKintBundle"
        }
    ],

    "require": {
        "php":                      ">=5.3.2",
        "symfony/framework-bundle": ">=2.0.0",
        "raveren/kint":             "dev-master"
    },

    "minimum-stability": "dev",

    "autoload": {
        "psr-0": {
            "Cg\\KintBundle": ""
        }
    },

    "target-dir": "Cg/KintBundle"
}

Then add your bundle to packagist.org. It is very simple, basically you just have to provide your git address and it will do the rest.

Once your bundle is available in packagist, then just add it as a dependency in the composer.json file for your symfony project. In my case I have:

"require": {
    ....
    "cg/kint-bundle": "*"
},

Then just run "composer update" in your symfony directory and that´s all! You don´t even need to update the autoload file, composer will do it for you. The only thing left would be to load the bundle in appkernel.php

Share:
11,016
IlyaDoroshin
Author by

IlyaDoroshin

Frontend developer. React+Redux.

Updated on June 16, 2022

Comments

  • IlyaDoroshin
    IlyaDoroshin almost 2 years

    I've just moved to Symfony 2.1, and I can't understand, how can I install my own bundles with Composer?

    It was very easy in 2.0.x in deps:

    [MyOwnBundle]
      [email protected]:weboshin_cms_bundle.git
      target=/bundles/My/OwnBundle
    

    After that I just triggered bin/vendors update and that was it!

    But now there's no deps file, and I supposed to do everything with Composer. Please give me any hints.