packagist.org上 创建一个Packages(comp
compsoer基本用法
https://docs.phpcomposer.com/01-basic-usage.html
如何创建一个依赖包
1.首先你得创建一个github账号
2.写好代码
3.在当前目录下新建一个文件composer.json(必要)
4.composer.json里信息格式看demo
5.github上创建一个项目,将自己代码提交到项目
6.packagist.org 点击提交 将github上项目地址复制过来check ,submit
![](https://img.haomeiwen.com/i6362658/fb0a0630a24e6448.png)
7.跳转后等update 完,一个依赖包就创建成功了
安装使用
在要使用的项目下 命令行里运行 composer require authors/resname
这时就会报错
重点 重点
[InvalidArgumentException]
Could not find a version of package authors/resname matching your minimum-stability (stable). Require it with an expl
icit version constraint allowing its desired stability.
[InvalidArgumentException]
Could not find a version of package authors/resname matching your minimum-stability (stable). Require it with an expl
icit version constraint allowing its desired stability.
错误提示是找不到依赖的版本
这里提示minimum-stability (stable)
composer.json里加上
"minimum-stability": "dev"
看依赖包 界面
![](https://img.haomeiwen.com/i6362658/d8b53ba5468af91d.png)
正常依赖包这里显示
![](https://img.haomeiwen.com/i6362658/a711f81563669c4b.png)
有坑
这里的版本不是每次提交就会产生的,也不是在composer.json里声明的
我提交了多次,改composer.json多次,这里就是没变化
然后请教了大神
这里的版本怎么来的
原来是要创建标签再提交代码
标签按格式 一般以v1.0.1 v2.0.1这样的格式
创建了标签,推送的时候记得也要提交标签
![](https://img.haomeiwen.com/i6362658/b7d3ea3764976537.png)
推送完记得update
![](https://img.haomeiwen.com/i6362658/7062fc8b0adf30eb.png)
之后就可以正常composer require安装使用了!
我创建的第一个依赖包 https://packagist.org/packages/hufang/neozip
文件批量打包下载