赞
踩
注:需要在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文件做如下修改:
- {
- "name": "lawademo/demo",
- "license": "Apache-2.0",
- "autoload": {
- "psr-4": {
- "lawademo\\": "src/"
- }
- },
- "require": {
- "php": ">=5.3.0"
- }
- }
4、在src目录下编写库文件
在src/test目录下编写Hello.php文件,内容如图所示:
接下来编写index.php测试文件并测试Hello.php文件功能是否正常
在执行index.php文件之前,先要执行composer update命令,然后执行index.php脚本,查看结果是否输出hello world
5、将代码提交到github仓库
注意:代码仅包含src目录和composer.json文件,vendor目录不要上传
- # 添加要提交文件
- git add .
-
- # 填写描述/说明
- git comment -m "说明"
-
- # 提交到本地仓
- git commit
-
- # 推送到github仓库
- git push
-
- # 或者使用下面命令推送到github仓库
- 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。