Composer需要本地和github存储库

时间:2019-04-15 11:08:15

标签: composer-php

在星期六,一个必需的Laravel软件包被完全从Github中删除。 但是我需要Laravel App的这种依赖关系。 我正在谈论的软件包是“ werneckbh / laravel-qr-code”及其依赖项“ werneckbh / qr-code” 我通过添加存储库本地定义从根本上修改了composer.json。

然后我跑

composer install

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "repositories": {
        "local": {
            "type": "path",
            "url": "vendor_local/werneckbh"
        }
    },
    "require": {
        "php": "^7.1.3",
        "ext-json": "*",
        "akaunting/money": "^1.0",
        "browner12/helpers": "^2.1",
        "cartalyst/stripe-laravel": "2.0.*",
        "doctrine/dbal": "^2.8",
        "fideloper/proxy": "^4.0",
        "illuminate/encryption": "^5.6",
        "illuminate/html": "^5.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0",
        "laravelcollective/html": "^5.4.0",
        "paypal/rest-api-sdk-php": "^1.13",
        "pusher/pusher-php-server": "^3.2",
        "sentry/sentry-laravel": "^0.11.0",
        "werneckbh/laravel-qr-code": "*",
        "werneckbh/qr-code": "*"
    },
    "require-dev": {
        "deployer/deployer": "^6.2",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "scripts": {
        "post-root-package-instaBut composer always tries to load from Github.
Is this possible to have a mixed setupll": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

composer.json,位于vendor_local / werneckbh / laravel-qr-code

{
    "name": "werneckbh/laravel-qr-code",
    "description": "QR Code Generator for PHP wrapper for Laravel",
    "license": "MIT",
    "authors": [
        {
            "name": "Bruno Werneck",
            "email": "brunovaulawerneck@gmail.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "werneckbh/qr-code": "^2.1"
    },
    "autoload": {
        "psr-4": {
            "LaravelQRCode\\": "src/"
        }
    },
    "extra": {
        "laravel": {
            "providers": [
                "LaravelQRCode\\Providers\\QRCodeServiceProvider"
            ],
            "aliases": {
                "QRCode": "LaravelQRCode\\Facades\\QRCode"
            }
        }
    }
}

composer.json,位于vendor_local / werneckbh / qr-code

{
    "name": "werneckbh/qr-code",
    "description": "QR Code Generator for PHP",
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "Bruno Vaula Werneck",
            "email": "brunovaulawerneck@gmail.com"
        }
    ],
    "require": {},
    "autoload": {
        "files": [
            "src/helpers/constants.php",
            "src/helpers/functions.php"
        ],
        "psr-4": {
            "QR_Code\\": "src/QR_Code/"
        }
    },
    "require-dev": {
        "khanamiryan/qrcode-detector-decoder": "^1.0",
        "phpunit/phpunit": "^6.5"
    }
}

但是作曲家总是尝试从Github加载。

我还尝试通过添加本地存储库

composer require local "vendor_local/werneckbh/laravel-qr-code"

但这会引发错误

 [InvalidArgumentException] 
 Could not find package local. 

这可能有混合设置吗?

2 个答案:

答案 0 :(得分:1)

据我了解,url值应该是包目录的路径(而不是包目录所在的供应商目录的路径)。因此,在您的情况下,可能是:

"repositories": {
    "local": {
        "type": "path",
        "url": "vendor_local/werneckbh/qr-code"
    },
   "local": {
        "type": "path",
        "url": "vendor_local/werneckbh/laravel-qr-code"
    }
}

此外,如果之前运行过composer update或拥有composer install文件,则应该运行composer.lock

答案 1 :(得分:0)

在对如何解决我的问题进行了更深入的研究之后,我发现了一种非常简单的方法来注入本地Packages。 我没有尝试强制composer从本地包composer.json加载,而是修改了autoload PSR-4定义。

第一步是从供应商文件夹中删除所有软件包,删除composer.lock,然后像这样修改根composer.json

...
"autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files": [
            "vendor_local/werneckbh/qr-code/src/helpers/constants.php",
            "vendor_local/werneckbh/qr-code/src/helpers/functions.php"
        ],
        "psr-4": {
            "App\\": "app/",
            "QR_Code\\": "vendor_local/werneckbh/qr-code/src",
            "LaravelQRCode\\": "vendor_local/werneckbh/laravel-qr-code/src"
        }
    },
...

正在运行

composer install

安装所有需要的软件包,此解决方案是更新保存