composer开发的一些坑

1.问题描述:
 Your configuration does not allow connections to xxxxxx See https://getcomposer.org/doc/06-config.md#secure-http for details.
解决办法:
 "config":{
        "secure-http":false
    },
2.问题描述:
Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your min                                      imum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more det                                      ails.
问题解决:
可能包不存在或者版本不存在
 

开发属于自己的composer

1.新建一个git仓库
备注:可以在github建立,如果要建立私有的composer,可以自己搭建git仓库

2.初始化composer文件
执行composer init
参考:https://getcomposer.org/doc/04-schema.md
{
    "name": "joyousphper/composer-demo",
    "description": "composer demo",
    "type": "library",
    "license": "MIT",
    "authors": [
        {
          "name": "joyousphper",
          "email": "joyousphper@gmail.com"
        }
    ],
    "minimum-stability": "stable",
    "require": {
        "php": ">=5.4.0"
    },
    "autoload": {
        "psr-4": {
          "Tools\\": "src/Tools/"
        }
    }

}

3.编写代码并推送git仓库
新建src/Tools/Common.php
<?php
namespace Tools;

class Common
{
    public static function demo()
    {
        return 'hello world';
    }

}
添加标签
git tag -a v0.1.1 -m'第二个版本'
git push origin tag v0.1.1

4.提交composer
https://packagist.org/packages/submit

5.查看提交composer包
https://packagist.org/packages/joyousphper/composer-demo

6.设置composer自动更新
6.1打开https://github.com/JoyousPHPer/composer-demo/settings/installations添加一个Packagist服务
6.2https://github.com/JoyousPHPer/composer-demo/settings/hooks设置hook,这里的apitoken可以从https://packagist.org/profile/查看

7.项目引用
{
    "name": "joyousphper/demo1",
    "description": "composer demo",
    "type": "project",
    "license": "MIT",
    "authors": [
        {
          "name": "joyousphper",
          "email": "joyousphper@gmail.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "joyousphper/composer-demo": "v0.1.*"
    }
}

8.使用案例
<?php
require __DIR__ . '/../vendor/autoload.php';
use Tools\Common;

echo Common::demo();