如何在Symfony 2.1中安装您自己的Composer捆绑包


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

我刚转到Symfony 2.1,我不明白,如何使用Composer安装我自己的捆绑包?

deps:中的2.0.x中非常容易

[MyOwnBundle]
  git=git@git.weboshin.ru:weboshin_cms_bundle.git
  target=/bundles/My/OwnBundle

在那之后,我刚刚触发了bin/vendors update,就这样!

但现在没有deps文件,我应该用Composer做所有的事情。请给我一些提示。

我找到了答案。

// 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"
}

将composer.json文件添加到您的捆绑包中。例如,我的一个捆绑包有这个:

{
    "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"
}

然后将你的捆绑包添加到packagist.org。这很简单,基本上你只需要提供你的git地址,它就可以完成剩下的工作。

一旦您的捆绑包在packagist中可用,那么只需将其作为依赖项添加到symfony项目的composer.json文件中即可。就我而言,我有:

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

然后只需在symfony目录中运行"composer update"即可!您甚至不需要更新自动加载文件,composer会帮您完成。剩下的唯一一件事就是在appkernel.php 中加载捆绑包