构建之前
- 申请github账号,并建好一个repositories。
- 用github登录packageList.
创建包
初始化仓库
mkdir -p /www/plan
cd /www/plan
echo "# plan" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:lujiang/plan.git
git push -u origin master
composer init
构建composer.json
{
"name": "lujiang618/plan",
"description": "plan",
"type": "project",
"licence": "MIT",
"authors": [
{
"name": "lujiang",
"email": "531432594@qq.com"
}
],
"require": {
"php":">=7.0.0"
},
"autoload": {
"psr-4":{
"Tools\":"src/Tools"
}
}
}
构建包
1.按照autoload中设置的,在根目录下建一个Tools的目录
2.在Tools目录写一个tools类
<?php
/**
* Created by PhpStorm.
* User: lujiang
* Date: 2018/9/30
* Time: 15:57
*/
namespace Tools;
class Tools
{
public function __construct() {
}
public static function hi() {
echo 'hi';
}
}
3.在根目录写一个测试类hi.php
<?php
/**
* Created by PhpStorm.
* User: lujiang
* Date: 2018/9/30
* Time: 16:06
*/
require_once './vendor/autoload.php';
use ToolsTools;
echo Tools::hi();
4.执行composer install
生成vendor目录
5.执行测试类,输出hi。如此一个包构建完成了
cd /www/plan
php hi.php
6.提交代码到github
git add .
git commit -am 'first'
git push
git tag -a v0.0.1 -m "first version"
git push origin v0.0.1