-
注册composer、github账号
-
在github上新增项目,并将项目克隆到本地环境
-
进入目录,新增src目录,新建Test.php文件
<?php
namespace Hinink;
class Test {
public function __construct(){
}
public function getDate(){
return date('Y-m-d H:i:s');
}
}
- composer构建项目
[root@hinink tmp]# composer init
Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
> 项目命名空间
Package name (<vendor>/<name>) [root/test]: hinink/test
> 项目描述
Description []: testing
> 作者信息
Author [沁 <zc520yzy@126.com>, n to skip]:
> 输入最低稳定版本
Minimum Stability []: dev
> 项目类型
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
> 授权类型
License []:
Define your dependencies.
> 依赖信息
Would you like to define your dependencies (require) interactively [yes]? yes
> 如果需要依赖,则输入要安装的依赖
Search for a package: php
Enter the version constraint to require (or leave blank to use the latest version): >=7.2
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [yes]? yes
Search for a package: laravel
Enter the version constraint to require (or leave blank to use the latest version):
Search for a package:
{
"name": "hinink/test",
"description": "testing",
"type": "library",
"require": {
"php": "^7.2",
"laravel/framework": "7.x-dev"
},
"license": "testing",
"authors": [
{
"name": "沁",
"email": "zc520yzy@126.com"
}
],
"minimum-stability": "dev"
}
> 确认构建项目,生成 composer.json
Do you confirm generation [yes]? yes
Would you like the vendor directory added to your .gitignore [yes]? yes
Would you like to install dependencies now [yes]? yes
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
- 修改composer.json配置
{
"name": "hinink/test",
"description": "testing",
"type": "library",
"require": {
"php": "^7.2",
"laravel/framework": "7.x-dev"
},
"license": "testing",
"authors": [
{
"name": "沁",
"email": "zc520yzy@126.com"
}
],
"minimum-stability": "dev",
#新增autoload自动加载,遵循psr-4规则
"autoload": {
"psr-4": {
"Stephen\\": "src/"
}
}
}
-
提交项目到github
-
在composer packagist提交项目,打开https://packagist.org/,点击右上角Submit,输入git地址,然后确认提交
-
在GitHub项目中,点击 Setting -> Webhooks -> add webhooks
-
git标签
git tag
git tag -a v1.0.0 -m '描述'
git push origin v1.0.0
在github项目中, 进入 release -> Draft a new release
10. 完成,在项目中执行
composer require hinink/test