当前位置:   article > 正文

使用composer编写自己的库_php composer使用自建仓库

php composer使用自建仓库

注:需要在windows上安装composer、git等软件

一、composer使用

详见原文:Composer 中文文档 | Composer 中文网

二、在github创建仓库、发布,最后在packagist上提交包

1、登录https://github.com,New repository创建仓库

 

2、创建仓库之后,我们可以使用git工具下载仓库代码

 命令:git clone https://github.com/xxx/lawademo.git

3、使用composer init进行初始化

 文件结构及composer.json内容,如下图所示: 

 不想命名空间为Lawademo\\Demo,有点长,对composer.json文件做如下修改:

  1. {
  2. "name": "lawademo/demo",
  3. "license": "Apache-2.0",
  4. "autoload": {
  5. "psr-4": {
  6. "lawademo\\": "src/"
  7. }
  8. },
  9. "require": {
  10. "php": ">=5.3.0"
  11. }
  12. }

4、在src目录下编写库文件

 在src/test目录下编写Hello.php文件,内容如图所示:

接下来编写index.php测试文件并测试Hello.php文件功能是否正常

 在执行index.php文件之前,先要执行composer update命令,然后执行index.php脚本,查看结果是否输出hello world

 5、将代码提交到github仓库

注意:代码仅包含src目录和composer.json文件,vendor目录不要上传

  1. # 添加要提交文件
  2. git add .
  3. # 填写描述/说明
  4. git comment -m "说明"
  5. # 提交到本地仓
  6. git commit
  7. # 推送到github仓库
  8. git push
  9. # 或者使用下面命令推送到github仓库
  10. git push -u origin main

6、在github.com发布版本

 7、在https://packagist.org/packages/submit上填写仓库地址

8、使用composer require xxx/lawademo,并编写index.php文件进行测试

注:其中index.php的相关操作同第4步的操作

三、可能出现的问题有:

Q1:unable to access 'https://github.com/xxx/yyy.git/': OpenSSL SSL_read: Connection was reset, errno 10054

A1:执行下面命令git config --global http.sslVerify false

Q2:git push超时问题

A2:通过​​​​​​https://websites.ipaddress.com/github.global.ssl.fastly.net#ipinfo​​​​​​​来查询github.com的ip地址,然后在windows系统 C:\Windows\System32\drivers\etc\hosts文件追加内容如下:

140.82.113.4 github.com

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/491915
推荐阅读
相关标签
  

闽ICP备14008679号