composer开发自定义包(基于git,Packagist)-(方式二)
Posted Json2011315
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了composer开发自定义包(基于git,Packagist)-(方式二)相关的知识,希望对你有一定的参考价值。
2.在github上新增项目,并将项目克隆到本地环境
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www
$ git clone git@github.com: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构建项目
4.修改composer.json文件
"name": "two/test",
"description": "pack test two",
"type": "library",
"require":
"php": "^7.2"
,
"license": "MIT",
"authors": [
"name": "json",
"email": "json_yin@fionacos.com"
],
"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
<?php
namespace Two;
class Tservice
public function __construct()
public function getDate()
return date('Y-m-d H:i:s');
/**
* tag 1.1
*/
public function getDatev2()
return date('Y-m-d H-i-s');
7.创建test.php测试文件
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Two\\Tservice;
$obj=new Tservice();
$time=$obj->getDate();
echo $time;
修改git忽略文件.gitignore(把改文件提交到远程仓库)【vendor文件可以不提交到远程仓库,获取代码没有vendor可以执行composer dump-autoload】
#/vendor/
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)
9.在composer packagist提交项目,打开https://packagist.org/,点击右上角Submit,输入git地址,然后确认提交(把项目传递到packages)
复制git仓库的地址
git仓库地址粘贴到packages然后点击Check
点击提交操作
项目提交成功
10.组件包打标签(不熟悉git命令点击查看)
10.1命令方式打tag(方法一)
github远程仓库,推送成功的标签
10.2直接在github打标签(方法二)
在github项目中, 进入 release -> Draft a new release->Publish release
标签创建成功
11 github标签打包成功后,packagist点击更新
12.laravel 项目。执行 composer require two/test
添加路由
文件目录:routes/web.php
Route::any('ziditwo',function()
$obj=new \\Two\\Tservice();
return $obj->getDate();
);
postman访问:
以上是关于composer开发自定义包(基于git,Packagist)-(方式二)的主要内容,如果未能解决你的问题,请参考以下文章