首页 > 代码库 > composer gitlab 搭建私包

composer gitlab 搭建私包

一、建立私包git

1、执行composer init 根据提示生成composer.json

2、编辑composer.json 目录格式

{
    "name": "iaround/lib",
    "description": "iaround lib",
    "license": "MIT","require": {
        "dingo/api": "1.0.x@dev",
        "predis/predis":"^1.1",
        "illuminate/redis":"^5.4",
        "cheprasov/php-redis-client": "^1.6",
        "webpatser/laravel-uuid": "2.*",
        "newiep/httpsqs": "dev-master",
        "stomp-php/stomp-php": "^4.2"
    },
    "autoload": {
        "psr-4": {
            "App\\Lib\\Cache\\": "src/Lib/Cache/",
            "App\\Lib\\DataStore\\": "src/Lib/DataStore/",
            "App\\Lib\\Enums\\": "src/Lib/Enums/",
            "App\\Lib\\I18N\\": "src/Lib/I18N/",
            "App\\Lib\\MemCache\\": "src/Lib/MemCache/",
            "App\\Lib\\Models\\": "src/Lib/Models/",
            "App\\Lib\\MQ\\": "src/Lib/MQ/",
            "App\\Lib\\SQS\\": "src/Lib/SQS/",
            "App\\Lib\\Struct\\": "src/Lib/Struct/",
            "App\\Lib\\Tools\\": "src/Lib/Tools/"
        },
        "files": [
            "src/Lib/Helps.php"
        ]
    },
    "minimum-stability": "stable"
}

3、提交代码到gitlab.

 

二、引用私包

1、以laravel框架为例,安装初始化laravel自行完成。

2、编辑laravel的composer.json 

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "minimum-stability": "dev",
    //私包配置修改1
    "repositories": [
        {
            "type": "git",
            "url": "http://g.x.com/private-package.git",
            "reference":"master"
        }
    ],
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0",
        "iaround/lib": "*" // 载入私包 修改2
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists(‘.env‘) || copy(‘.env.example‘, ‘.env‘);\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "secure-http": false //开启http请求 修改3
    }
}

3、最后

composer update 

大功告成

composer gitlab 搭建私包