wilon.github.io
wilon.github.io copied to clipboard
PHPer如何发布 composer 包?
以 https://github.com/wilon/simple-php-debug 为例
1. 提交源码
-
PHP源码
src/SimpleDebug.php
-
编写composer.json文件
{
// 包名
"name": "wilon/simple-php-debug",
// 包描述
"description": "Simple PHP Debug, better output and write log.",
// 许可证
"license": "MIT",
// 主页
"homepage": "https://wilon.github.io",
// 支持
"support": {
// 提问
"issues": "https://github.com/wilon/simple-php-debug/issues",
// 源码
"source": "https://github.com/wilon/simple-php-debug"
},
// 关键字
"keywords": ["php", "debug", "dump"],
// 作者
"authors": [
{
"name": "Weilong Wang",
"email": "[email protected]"
}
],
// 包依赖
"require": {
"php": ">=5.3"
},
// 自动加载
"autoload": {
// 按文件
"files": [
"src/SimpleDebug.php"
],
// 按psr-4,即按命名空间自动引入
"psr-4": {
"Illuminate\\Database\\": ""
}
},
// 配置
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}
- 添加版本号
git tag 0.1.0 && git push origin --tags
2. https://packagist.org/ 注册登录
- 右上角 Submit
- 填入GitHub 项目地址
3. 配置GitHub项目
- 打开GitHub项目
- Settings -> Integrations & services -> Services -> Add Service
- 搜索 Packagist 点击
- 输入https://packagist.org/profile/ 的User和Token。
测试下 composer require xxx/xxxx