第一步新建文件夾
mkdir httptool
cd httptool
初始化composer
composer init
Welcome to the Composer config generator
# 交互引導(dǎo)初始化
This command will guide you through creating your composer.json config.
# 填寫包名,最好填寫github名/包名
Package name (<vendor>/<name>) [afishpapa/httptool]: afishpapa/httptool
# 包描述
Description []: a simple httptool
# 作者
Author [laoxie <116265858@qq.com>, n to skip]:
laoxie <116265858@qq.com>
# 最低穩(wěn)定性, 是指你可以接受的最低穩(wěn)定性級別
# dev級別最低,表示你的項(xiàng)目可以安裝全部穩(wěn)定性級別的擴(kuò)展
# stable級別最高,表示只能安裝stable的擴(kuò)展
# 級別從低到高排序:dev,alpha,beta,RC,stable,^,~
Minimum Stability []: stable
# 包類型,庫,項(xiàng)目,還是composer插件,metapackage是一組依賴包的集合,安裝這種包就等于安裝一組包
Package Type (e.g. library, project, metapackage, composer-plugin) []: project
# 開源協(xié)議
License []: MIT
# 定義依賴,這里沒有
Define your dependencies.
Would you like to define your dependencies (require) interactively [yes]? no
# 定義開發(fā)依賴,這里沒有
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
# 添加PSR-4 映射 默認(rèn) src/
Add PSR-4 autoload mapping? Maps namespace "Afishpapa\Httptool" to the entered relative path. [src/, n to skip]: src/
# 至此結(jié)束,最終在根目錄生成以下文件:
PS D:\workspace\composertest\httptool> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2023/4/7 22:10 .idea
d----- 2023/4/7 22:02 src
d----- 2023/4/7 22:02 vendor
-a---- 2023/4/7 22:02 388 composer.json
# 其中composer.json
{
"name": "afishpapa/httptool",
"description": "simple httptool",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"Afishpapa\\Httptool\\": "src/"
}
},
"authors": [
{
"name": "laoxie",
"email": "116265858@qq.com"
}
],
"minimum-stability": "stable",
"require": {}
}
Do you confirm generation [yes]? yes
Generating autoload files
Generated autoload files
PSR-4 autoloading configured. Use "namespace Afishpapa\Httptool;" in src/
Include the Composer autoloader with: require 'vendor/autoload.php';
添加內(nèi)容
PS D:\workspace\composertest\httptool> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2023/4/7 22:25 .idea
d----- 2023/4/7 22:26 example //demo代碼,介紹你這個(gè)包怎么調(diào)用
d----- 2023/4/7 22:25 src //核心科技
d----- 2023/4/7 22:26 test //測試單例
d----- 2023/4/7 22:02 vendor
-a---- 2023/4/7 22:13 378 composer.json
-a---- 2023/4/7 22:13 README.md //讀我
github新建一個(gè)空倉庫,上傳剛建的擴(kuò)展包
echo "# httptool" >> README.md
git init
git add README.md
git add .
git commit -m "first commit"
git branch -M main
git remote add origin
# 這里填寫你自己的
git@github.com:afishpapa/httptool.git
git push -u origin main
注冊packagist.org賬號
可以通過oauth2.0使用GITHUB賬號登錄packagist.org
點(diǎn)擊submit,輸入github的鏈接
check通過之后就可以了,網(wǎng)站會(huì)去自動(dòng)去下載代碼,
如果以后包有改動(dòng)需要再來這里點(diǎn)擊update
composer create-project試試看看
PS composer create-project afishpapa/httptool
Creating a "afishpapa/httptool" project at "./httptool"
In CreateProjectCommand.php line 424:
Could not find package afishpapa/httptool with stability stable.
這個(gè)時(shí)候還不行,因?yàn)間ithub還沒有發(fā)布穩(wěn)定版本
github release
先去打個(gè)tag
PS D:\workspace\composertest\httptool> git tag 1.0.0
PS D:\workspace\composertest\httptool> git push --tags
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:afishpapa/httptool.git
* [new tag] 1.0.0 -> 1.0.0
打好包的
composer create-project 再試試看
PS > composer create-project afishpapa/httptool test1
Creating a "afishpapa/httptool" project at "./test1"
Info from https://repo.packagist.org: #StandWithUkraine
Installing afishpapa/httptool (1.0.0)
- Downloading afishpapa/httptool (1.0.0)
- Installing afishpapa/httptool (1.0.0): Extracting archive
Created project in D:\workspace\composertest\httptool\test1
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
No installed packages - skipping audit.