转载: https://www.jianshu.com/p/3c53c8388dba

github创建一个空的项目

不在赘述可以百度

做自己的包,给大家展示一下我的demo

在这里插入图片描述

初始化自己的包

根目录下执行 composer init 会让你自己填写内容,不知道怎么写的可以去百度

➜  test git:(master) ✗ composer init


  Welcome to the Composer config generator



This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [zouzhanhao/test]:
Description []: 测试
Author [, n to skip]: zouzhanhao <1021314274@qq.com>
Minimum Stability []: dev
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
License []:MIT

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? yes
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [yes]?
Search for a package:

{
    "name": "zouzhanhao/test",
    "description": "测试",
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "zouzhanhao",
            "email": "1021314274@qq.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {}
}

Do you confirm generation [yes]? yes
Would you like the vendor directory added to your .gitignore [yes]? ye
Please answer yes, y, no, or n.
Would you like the vendor directory added to your .gitignore [yes]? yes

生成的json需要加入自动加载

    "autoload": {
        "psr-4":{
            "test\\":"src"
        }
    }

加入之后的样子,这里要注意的是自动加载的路径 遵循psr-4标准

在这里插入图片描述

测试的话,你可以直接composer install 测试 ,这里用空在写

关联github 我用的SSH方式,

➜  test git init
已初始化空的 Git 仓库于 /WWW/test/.git/
➜  test git:(master) ✗ git add .
➜  test git:(master) ✗ git commit -m 'first'
[master(根提交) 6686410] first
 5 files changed, 85 insertions(+)
 create mode 100644 .idea/misc.xml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/test2.iml
 create mode 100644 .idea/workspace.xml
 create mode 100644 src/test.php
➜  test git:(master) git remote add origin git@github.com:1021314274/test.git
➜  test git:(master) git push -u origin master
枚举对象: 9, 完成.
对象计数中: 100% (9/9), 完成.
使用 4 个线程进行压缩
压缩对象中: 100% (8/8), 完成.
写入对象中: 100% (9/9), 1.80 KiB | 368.00 KiB/s, 完成.
总共 9 (差异 0),复用 0 (差异 0)
To github.com:1021314274/test.git
 * [new branch]      master -> master
分支 'master' 设置为跟踪来自 'origin' 的远程分支 'master'。

提交包

packaglist

在这里插入图片描述

显示submit 表示包没有问题,直接提交就行了


在这里插入图片描述

包生成好了,但是没有版本 你直接composer是不会成功的,所以需要生成版本

git tag v1.0.0
git push --tag

最后找一个项目 composer require zouzhanhao/test 完事