新建一个空的 symfony 项目
php composer.phar create-project symfony/framework-standard-edition demo/ 2.4.1
cd demo
生成一个新的捆绑包
(例如src/Company/DemoBundle)
php app/console generate:bundle
cd src/Company/DemoBundle/
在src/Company/DemoBundle中初始化你的github仓库
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
添加 composer.json 文件
src/Company/DemoBundle/composer.json:
{
"name" : "company/demobundle",
"description" : "A demo bundle",
"type" : "symfony-bundle",
"authors" : [{
"name" : "demo",
"email" : "demo@company.com"
}],
"keywords" : [
"demo bundle"
],
"license" : [
"MIT"
],
"require" : {
},
"autoload" : {
"psr-0" : {
"Company\\DemoBundle" : ""
}
},
"target-dir" : "Company/DemoBundle",
"repositories" : [{
}],
"extra" : {
"branch-alias" : {
"dev-master" : "some_version-dev"
}
}
}
现在你有了你的包的基本结构
在其他项目中使用
composer.json:
[...]
"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(),
继续努力
- 您可以在
src/Company 文件夹中克隆您的DemoBundle,然后手动安装它
- 您可以使用符号链接
结论
您可以在您的第一个项目中开发和测试您的包,并在您的第二个项目中将它与 github 和 composer 一起使用。