1、初始化包
2、將代碼推送到github遠(yuǎn)程倉(cāng)庫(kù)
3、為寫好擴(kuò)展包打上tag標(biāo)簽標(biāo)記當(dāng)前代碼版本
4、將包發(fā)布到包管理平臺(tái)
Creates a basic composer.json file in current directory
composer init
composer init 按照引導(dǎo)就可以生成了 , 詳細(xì)的引導(dǎo)解釋如下
This command will guide you through creating your composer.json config.
# 1. 輸入項(xiàng)目命名空間,我是按github賬號(hào)名/倉(cāng)庫(kù)名
# 注意/必須要符合 [a-z0-9_.-]+/[a-z0-9_.-]+
Package name (/) [root/test_composer]:yourname/projectname
# 2. 項(xiàng)目描述
Description []:這是一個(gè)測(cè)試composer init 項(xiàng)目
# 3. 輸入作者信息,直接回車可能出現(xiàn)如下提示,有的系統(tǒng)可以直接回車,具體為什么?這里不詳細(xì)介紹
Invalid author string. Must be in the format: John Smith# 3.1. 注意必須要符合 John SmithAuthor [Alan.Liu<5425902+liuyuanshan11@user.noreply.gitee.com>, n to skip]: liuyuanshan
# 4. 輸入最低穩(wěn)定版本,stable, RC, beta, alpha, dev
Minimum Stability []:dev
# 5. 輸入項(xiàng)目類型
Package Type (e.g. library, project, metapackage, composer-plugin) []:library
# 6. 輸入授權(quán)類型,默認(rèn)回車
License []:
Define your dependencies.
# 7. 輸入依賴信息,默認(rèn)回車
Would you like to define your dependencies (require) interactively [yes]?
# 7.1. 如果需要依賴,則輸入要安裝的依賴
Search for a package:php
# 7.2. 輸入版本號(hào)
Enter the version constraint to require (or leave blank to use the latest version): >=7.0.0
# 如需多個(gè)依賴,則重復(fù)以上兩個(gè)步驟(7.1/7.2),沒有則默認(rèn)回車
Search for a package:
# 8. 是否需要require-dev,
Would you like to define your dev dependencies (require-dev) interactively [yes]?
{
"name": "liuyuanshan11/demo",
"description": "this is test project",
"type": "library",
"require-dev": {
"php": "7.0.0"
},
"autoload": {
"psr-4": {
"Liuyuanshan11\\Demo\\": "src/"
}
},
"authors": [
{
"name": "liuyuanshan"
}
],
"minimum-stability": "dev",
"require": {}
}
# 9. 是否生成composer.json
Do you confirm generation [yes]?
# 現(xiàn)在安裝依賴項(xiàng)嗎
Would you like to install dependencies now [yes]?
隨后調(diào)整composer.json配置文件,內(nèi)容示例如下:
{
"name": "liuyuanshan11/demo",
"description": "this is test project",
"homepage":"https://github.com/liuyuanshan11/demo",
"require": {
"php":">=7.0",
"ext-json": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"Liuyuanshan11\\Demo\\": "src/"
}
},
"authors": [
{
"name": "liuyuanshan",
"email": "1019213039@qq.com",
"homepage":"https://github.com/liuyuanshan11/demo"
}
],
"minimum-stability": "dev"
}
生成vendor目錄
composer update
編寫測(cè)試代碼
src/Test.php
后再根目錄 創(chuàng)建一下 index.php 引入類
index();
執(zhí)行自動(dòng)加載命令,為創(chuàng)建的類文件指定自動(dòng)加載命名空間
composer dump-autoload -o
將代碼推送到github遠(yuǎn)程倉(cāng)庫(kù)# 將代碼推送到master遠(yuǎn)程倉(cāng)庫(kù)
git push origin master
為寫好擴(kuò)展包打上tag標(biāo)簽標(biāo)記當(dāng)前代碼版本為當(dāng)前版本打上tag標(biāo)簽,在發(fā)布包管理平臺(tái)時(shí)會(huì)使用到,因?yàn)榘睦∈歉鶕?jù)版本拉取的,默認(rèn)拉取最新tag標(biāo)簽的版本包
# 創(chuàng)建標(biāo)簽
git tag v1.0.0
# 查看所有標(biāo)簽
git tag
# 遠(yuǎn)程推送到github倉(cāng)庫(kù)
git push origin master --tags
將包發(fā)布到包管理平臺(tái)先到包管理平臺(tái)進(jìn)行注冊(cè)登錄,這里我選擇了github賬號(hào)進(jìn)行授權(quán)登錄比較方標(biāo)
https://packagist.org/
點(diǎn)擊【Submit】按鈕,將github倉(cāng)庫(kù)地址放入解析框,最后點(diǎn)擊【Check】便可完成包的發(fā)布
查看發(fā)布的包與迭代中的包版本
下載包,默認(rèn)拉取最新tag包
composer require liuyuanshan11/sd-micro-service-client
使用包
use liuyuanshan11\SdMicroServiceClient\MicroService;
$services = [
'queue' =>'https://queue-service.sumian.com',
'console' =>'https://console-service.sumian.com',
'organization' =>'https://organization-service.sumian.com',
'liu' =>'http://sdapi.test.top'
];
$obj = new MicroService('appId', 'appSecret', $services);
var_dump($obj->get('console')->act('controller', 'action', ["key01" =>"value01"]));
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
新聞標(biāo)題:制作composer包提供sdk擴(kuò)展-創(chuàng)新互聯(lián)
文章來源:http://jinyejixie.com/article22/ghgcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、外貿(mào)建站、軟件開發(fā)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容