将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”,这就是全部!你甚至不需要更新autoload文件,作曲家会为你做。剩下的唯一东西就是加载appkernel.php中的包
**随着Symfony的2.1也可以使用旧的依赖管理!**你必须创建一个'composer.json'文件告诉作曲什么是你的依赖。你应该看看[Symfony标准版的一个](https://github.com/symfony/symfony-standard/blob/master/composer.json)。然后为你的包创建另一个'composer.json'。 – Florent
@Florent,请注意Composer工具'composer-php'已经有一个标签。 – Charles