composer开发自定义包(基于git,Packagist)-(方式二)

1.注册composer、github账号

2.在github上新增项目,并将项目克隆到本地环境

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www
$ git clone [email protected]:Yinjinshui/pack-test-two.git
Cloning into 'pack-test-two'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 33 (delta 7), reused 22 (delta 5), pack-reused 0
Receiving objects: 100% (33/33), 6.49 KiB | 1.62 MiB/s, done.
Resolving deltas: 100% (7/7), done.

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www
$ cd pack-test-two/

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ ls
 README.md  

3.composer构建项目
composer开发自定义包(基于git,Packagist)-(方式二)_第1张图片
4.修改composer.json文件

{
    "name": "two/test",
    "description": "pack test two",
    "type": "library",
    "require": {
        "php": "^7.2"
    },
    "license": "MIT",
    "authors": [
        {
            "name": "json",
            "email": "[email protected]"
        }
    ],
    "minimum-stability": "dev",
    "autoload": {
        "psr-4": {
            "Two\\": "src/"
        }
    }
}

5.修改完composer.json,需要执行composer dump-autoload

D:\laravel_www\pack-test-two>composer dump-autoload
Generating autoload files
Generated autoload files

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ ls
composer.json  composer.lock  README.md   vendor/

6 创建src目录(创建服务文件)

创建Tservice.php

7.创建test.php测试文件

getDate();
echo $time;

composer开发自定义包(基于git,Packagist)-(方式二)_第2张图片
修改git忽略文件.gitignore(把改文件提交到远程仓库)【vendor文件可以不提交到远程仓库,获取代码没有vendor可以执行composer dump-autoload】

 #/vendor/

composer开发自定义包(基于git,Packagist)-(方式二)_第3张图片

8.提交文件到github远程仓库

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in composer.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in composer.lock.
The file will have its original line endings in your working directory.
g
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ git commit -m "备注"
[master 049278a] 备注
 5 files changed, 189 insertions(+), 13 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 composer.json
 create mode 100644 composer.lock
 create mode 100644 test.php

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ git push origin master
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 2.10 KiB | 1.05 MiB/s, done.
Total 8 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:Yinjinshui/pack-test-two.git
   18f75e7..049278a  master -> master

Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)

composer开发自定义包(基于git,Packagist)-(方式二)_第4张图片
9.在composer packagist提交项目,打开https://packagist.org/,点击右上角Submit,输入git地址,然后确认提交(把项目传递到packages)

composer开发自定义包(基于git,Packagist)-(方式二)_第5张图片 复制git仓库的地址
composer开发自定义包(基于git,Packagist)-(方式二)_第6张图片

git仓库地址粘贴到packages然后点击Check
composer开发自定义包(基于git,Packagist)-(方式二)_第7张图片点击提交操作

composer开发自定义包(基于git,Packagist)-(方式二)_第8张图片项目提交成功
composer开发自定义包(基于git,Packagist)-(方式二)_第9张图片10.组件包打标签(不熟悉git命令点击查看)

10.1命令方式打tag(方法一)
composer开发自定义包(基于git,Packagist)-(方式二)_第10张图片
github远程仓库,推送成功的标签
composer开发自定义包(基于git,Packagist)-(方式二)_第11张图片
10.2直接在github打标签(方法二)

在github项目中, 进入 release -> Draft a new release->Publish release
composer开发自定义包(基于git,Packagist)-(方式二)_第12张图片composer开发自定义包(基于git,Packagist)-(方式二)_第13张图片
composer开发自定义包(基于git,Packagist)-(方式二)_第14张图片标签创建成功
composer开发自定义包(基于git,Packagist)-(方式二)_第15张图片
11 github标签打包成功后,packagist点击更新

composer开发自定义包(基于git,Packagist)-(方式二)_第16张图片
12.laravel 项目。执行 composer require two/test

composer开发自定义包(基于git,Packagist)-(方式二)_第17张图片
添加路由
文件目录:routes/web.php

Route::any('ziditwo',function(){
    $obj=new \Two\Tservice();
    return $obj->getDate();
});

postman访问:
composer开发自定义包(基于git,Packagist)-(方式二)_第18张图片

你可能感兴趣的:(composer,php)