1.在gitee上创建项目sumpay
2. git clone https://gitee.com/meetrice/sumpay.git
3.compose初始化
cd sumpay composer init
Minimum Stability []: stable
Package Type []: library
License []: MIT
define your dependencies n
define your dev dependencies n
其他默认
4.在sumpay目录下创建 src/HelloWorld.php
<?php /** * Created by PhpStorm. * User: scort * Date: 18-3-11 * Time: 上午11:16 */ namespace HelloWorld; class HelloWorld { // 作者 protected $author; /** * HelloWorld constructor. * @param string $author */ public function __construct($author = 'scort') { $this->author = $author; } /** * 执行方法 * @return string */ public function info() { $info = "Hello World ! "; $info .= " --Power By "; $info .= $this->author . " "; return $info; } }
5.在composer.json文件中增加
"require": { "php" : ">=5.6" }, "autoload": { "psr-4": { "HelloWorld\" : "src/" } }
6.提交到gitee
git add . git commit -m 'helloWorld' git tag 1.0.0 git push origin master --tag
7.将git地址提交到packagist中
https://packagist.org/packages/submit
在Repostory Url中输入gitee地址
点击Check,然后Submit
8.配置gitee更新后packagist自动更新
点击packagist右上角 用户名 Profile 然后点击show API Token 显示token
在gitee项目->管理->WebHooks 里 添加WebHooks
URL:填写
https://packagist.org/api/update-package?username=平台用户名&apiToken=上面显示的API_TOKEN
完成!
9.使用实例
创建示例项目目录test
cd test composer init 一直回车 composer install composer require meetrice/sumpay
在test根目录下新建index.php
<?php require "vendor/autoload.php"; use HelloWorldHelloWorld; $h = new HelloWorld('meetrice'); echo $h->info();
执行
php index.php
Hello World ! --Power By meetrice
升级指定包
composer update meetrice/sumpay