将composer.json文件添加到您的包中。例如,我为我的一个bundle编写了以下内容:
{
"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"
}
然后将您的 bundle 添加到 packagist.org。这非常简单,您只需要提供您的 git 地址,它将处理其他事情。
一旦您的 bundle 在 packagist 上可用,那么只需将其作为 Symfony 项目的 composer.json 文件中的依赖项添加即可。在我的案例中,我有:
"require": {
....
"cg/kint-bundle": "*"
},
只需要在Symfony目录中运行“composer update”即可,就这么简单!甚至无需更新自动加载文件,Composer会为您完成。剩下的唯一事情就是在appkernel.php中加载bundle。
composer.json
文件来告诉Composer您的依赖关系是什么。您应该查看Symfony标准版的文件。然后为您的bundle创建另一个composer.json
文件。 - Florentcomposer-php
。 - Charles