1.建立yii2-helloxd仓库

flyaction/yii2-helloxd

2.添加仓库内容,并初始化composer,提交到packagist

2.1 添加仓库内容,并初始化composer,
mkdir composer-yii2 //创建目录
cd composer-yii2
git clone https://github.com/flyaction/yii2-helloxd.git //克隆
cd yii2-helloxd
composer init

        This command will guide you through creating your composer.json config.

        Package name (<vendor>/<name>) [root/hello-yii2]: flyaction/yii2-helloxd

        Description []: say hello for yii

        Author [, n to skip]: n

        Minimum Stability []: dev

        Package Type (e.g. library, project, metapackage, composer-plugin) []: yii2-extension

        License []: BSD-3-Clause

        Define your dependencies.

        Would you like to define your dependencies (require) interactively [yes]? no

        Would you like to define your dev dependencies (require-dev) interactively [yes]? no

        {

           "name": "flyaction/yii2-helloxd",

           "description": "say hello for yii",

           "type": "yii2-extension",

           "license": "BSD 3-Clause",

           "minimum-stability": "dev",

           "require": {}

        }

    Do you confirm generation [yes]? yes

    Would you like the vendor directory added to your .gitignore [yes]? yes

2.2修改生成的composer.json

 {

       "name": "flyaction/yii2-helloxd",

       "description": "say hello for yii2",

       "type": "yii2-extension",

       "license": "BSD-3-Clause",

       "require": {

       "yiisoft/yii2": "*"

   },

   "minimum-stability": "dev",

   "autoload": {

       "psr-4": {

           "flyaction\helloxd\": ""

       }

    }

}

2.3在yii2-helloxd 下新建Helloxd.php,内容如下

<?php
namespace flyaction\helloxd;
class Helloxd
{
   public static function sayHello()
   {
       return "hello";
   }
}

2.4提交至仓库,并打上标签
git commit -a -m 'first commit'
git push
git tag -a v1.0.0 -m '1.0.0版本'
git push --tags

3.发布到packagist

进入https://packagist.org/,登陆后点击右上角的submit按钮,之后输入你的 github 仓库地址,点击 check 之后 submit
仓库地址: https://github.com/flyaction/yii2-helloxd.git

4.测试使用

进入我们的yii项目
composer require flyaction/yii2-helloxd

安装完毕后,进入一个控制器的方法,写入一些内容即可
echo \flyaction\helloxd\Helloxd::sayHello();