composer-创建自己的依赖库

1.环境

  • 码云账号(或者GitHub)码云地址
  • composer 官方仓库账号 Packagist composer官方仓库
  • 安装composer

2.步骤

2.1 发行composer的依赖包是需要从git 或者svn里拉取的,所以得先在码云里创建一个仓库

composer-创建自己的依赖库_第1张图片

2.2 依赖包中必须有composer.json配置标明名字依赖等信息,配置大概如下,配置完后提交到码云仓库中

{

    "name": "angryshan/lss",
    "type": "library",
    "description": "angryshan lss",
    "keywords" : ["angryshan", "lss"],
    "authors": [
        {
            "name": "angryshan",
            "email": "[email protected]"
        }
    ],
    "require": {
        "php": ">=7.4.0",
        "ext-pdo": "*"
    },

    "autoload": {
        "psr-4": {
            "angryshan\\lss\\": "src/"
        }
    }
}

注意:name 必须包含’/'符号,并且这个名字在composer require 下来后会自动生成对应名字的文件夹,这里的require 后文件夹是 vendor/angryshan/lss

composer-创建自己的依赖库_第2张图片

2.3 提交到git完成后,创建一个发行版本

composer-创建自己的依赖库_第3张图片

2.4 完成后登录https://packagist.org ,点击右上角submit按钮,填写git地址,然后点击check

composer-创建自己的依赖库_第4张图片

2.5 成功
composer-创建自己的依赖库_第5张图片
2.6 项目运用

composer require angryshan/lss dev-master

3.composer require报错

一、Could not find package angryshan/lss. It was however found via repository search, which indicates a consistency issue with the repository.

解决办法:先切换一下composer镜像

#查看源配置
composer config -g -l
#切换为阿里云源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
#切换会原来的源
composer config -g repo.packagist composer https://repo.packagist.org

你可能感兴趣的:(composer,git,github)