沙滩星空的博客沙滩星空的博客

创建自己的composer包

创建一个git软件仓库

在 github , gitee 等平台上创建一个不包含任何文件空仓库。不包含 .gitignore,开源许可证等文件。
这些文件后续 git 手动提交。

初始化本地仓库

创建一个 composer.json 文件

composer.json 文件可以去网上参考可用模板,也可以使用 composer init 命令创建。

务必明白 composer.json 几个重要条目的意义。

提交到软件仓库

git tag v1.0.0
git push origin --tags
git add .
git commit -m "in order to build my packagist"
git push

Git标签

  • 查看: git tag
  • 打标签(默认为最新commit, 可指定): git tag v1.0.1, git tag v2.0.1 37c8036
  • 带说明的标签: git tag -a v1.0.1 -m "标签说明"
  • 删除标签: git tag -d v1.0.1
  • 删除远程标签: git push origin :refs/tags/v1.0.1
  • 推送标签到远程: git push origin v1.0.1 or git push origin --tags

到composer官网提交

https://packagist.org/packages/submit

输入仓库链接,填写包名,确认包名是否有重复。提交。

使用

composer require 名称:分支

例:

composer require catmes/log

安装时可能提示错误:

      [RuntimeException]                                                                                                      
      No composer.json present in the current directory (./composer.json), this may be the cause of the following exception.  
                                                                                                                              
                                                                                                                                                    
      [InvalidArgumentException]                                                                                                                    
      Could not find a version of package catmes/log matching your minimum-stability (stable). Require it with an explicit version constraint allo  
      wing its desired stability.  

原因:

  1. 当前路径没有 composer.json 文件。但报错后,马上自动创建了。内容为 {}
  2. composer包没有可用的稳定版本。git 提交时,给包打一个tag,比如1.0.0。
    如没有指定tag,默认为dev-master,故无法安装。可以指定dev-master分支安装。
composer require catmes/log:dev-master

制作一个简单的composer包 https://blog.csdn.net/qq_31424153/article/details/85093394
packagist composer包发布 - 第三方git平台push时自动触发WebHook https://blog.csdn.net/u012819495/article/details/108735598
Git 标签tag命令介绍 https://blog.csdn.net/weixin_45797022/article/details/121064882

未经允许不得转载:沙滩星空的博客 » 创建自己的composer包

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址