--name: 包的名称。
--description: 包的描述。
--author: 包的作者。
--homepage: 包的主页。
--require: 需要依赖的其它包,必须要有一个版本约束。并且应该遵循 foo/bar:1.0.0 这样的格式。
--require-dev: 开发版的依赖包,内容格式与 --require 相同。
--stability (-s): minimum-stability 字段的值。
composer init 这个命令将引导您完成创建您的composer.json配置
Package name (/) [sen/composer-plug]: sen/test
Description []: 测试包
Author [孟森 <626512443@qq.com>, n to skip]: 孟森 <626512443@qq.com>
Minimum Stability []: dev
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
License []: MIT
Define your dependencies.
Would you like to define your dependencies (require) interactively [yes]? yes
Search for a package: medoo
[0] catfan/medoo
[1] awheel/medoo-model
[2] bearlikelion/medoo-provider
Enter package to add, or the complete package name if it is not listed: 0
Enter the version constraint to require (or leave blank to use the latest version):
Using version ^1.2 for catfan/medoo
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
{
"name": "sen/test",
"description": "测试包",
"type": "library",
"require": {
"catfan/medoo": "^1.2"
},
"license": "MIT",
"authors": [
{
"name": "孟森",
"email": "626512443@qq.com"
}
],
"minimum-stability": "dev"
}
Do you confirm generation [yes]? yes
生成如下composer.json
{
"name": "sen/test",
"description": "测试包",
"type": "library",
"require": {
"catfan/medoo": "^1.2"
},
"license": "MIT",
"authors": [
{
"name": "孟森",
"email": "626512443@qq.com"
}
],
"minimum-stability": "dev"
}
常用参数
{
"name": "sen/test", //包名
"description": "测试包", //描述
"type": "library", //类型默认为 library 可选(library、project、metapackage、composer-plugin)
"keywords":"test", //关键字
"homepage":"http://www.baidu.com", //项目主页
"time":"2017-04-16", //版本发布时间
"require": { //必须的软件包列表
"catfan/medoo": "^1.2"
},
"require-dev":{ //这个列表是为开发或测试等目的,额外列出的依赖
"monolog/monolog": "^1.2"
},
"license": "MIT", //许可协议
"support": { //获取项目支持相关信息对象
"email": "support@example.org",
"irc": "irc://irc.freenode.org/composer"
}
"authors": [ //包的作者。这是一个对象数组
{
"name": "孟森",
"email": "626512443@qq.com"
}
],
"minimum-stability": "dev", //这定义了通过稳定性过滤包的默认行为。默认为 stable(稳定)。因此如果你依赖于一个 dev(开发)包,你应该明确的进行定义。
"prefer-stable": true, //当此选项被激活时,Composer 将优先使用更稳定的包版本
"suggest": { //建议安装的包,它们增强或能够与当前包良好的工作.格式如下,版本约束变成了描述信息
"monolog/monolog": "Allows more advanced logging of the application flow"
},
"autoload": { //autoloader 的自动加载映射
"psr-4": {
"Monolog\\": "src/",
"Vendor\\Namespace\\": ""
},
"classmap": ["src/", "lib/", "Something.php"],//你可以用 classmap 生成支持支持自定义加载的不遵循 PSR-0/4 规范的类库。要配置它指向需要的目录,以便能够准确搜索到类文件。
"files": ["src/MyLibrary/functions.php"], //如果你想要明确的指定,在每次请求时都要载入某些文件,那么你可以使用 'files' autoloading
},
"scripts": { //[Composer允许你在安装过程中的各个阶段挂接脚本更多细节和案例请查看脚本](http://docs.phpcomposer.com/articles/scripts.html)。
"post-update-cmd": "MyVendor\\MyClass::postUpdate",
"post-package-install": [
"MyVendor\\MyClass::postPackageInstall"
]
}
}