Composer/Symfony: 依赖问题

Composer/Symfony: dependency issues

上下文

我目前正在开发一个基于 Symfony 4.4 并部署在 Platform.sh.

上的 OroPlatform 项目

我在部署的构建阶段遇到了以下问题:

它运行良好,但昨天由于 Github OAuth 令牌更改,我不得不将作曲家版本升级到最新的 1.X:https://nono.ma/github-oauth-token-for-github-com-contains-invalid-characters-on-composer-install

问题

所以,我仍然面临 4.X 版本和 5.X 版本的这个问题。

我试过用这种方式安装我的项目的依赖项:composer install -n -o -a但是错误仍然存​​在。

我正在寻找一种方法来强制我的项目使用位于我的应用程序 vendor 文件夹中的依赖项,而不是全局安装的依赖项。这是 Platform.sh 服务器上问题的屏幕截图:

这里是我的应用程序和作曲家在 Platform.sh 服务器上的路径模式:

/app
|
|__/vendor/symfony-process
|
|__/.global/vendor/symfony-process

我的composer.json:

{
    "name": "oro/platform-application",
    "description": "Oro Platform Empty Application",
    "homepage": "https://github.com/oroinc/platform-application.git",
    "license": "MIT",
    "autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "src/AppKernel.php",
            "src/AppCache.php",
            "vendor/oro/platform/guzzle/Client.php"
        ],
        "exclude-from-classmap": [
            "/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php",
            "**/Tests/"
        ]
    },
    "repositories": {
        "composer": {
            "type": "composer",
            "url": "https://packagist.orocrm.com"
        }
    },
    "require": {
        "php": "~7.3.13 || ~7.4.2",
        "oro/platform": "4.1.*",
        "oro/platform-serialised-fields": "4.1.*",
        "oro/oauth2-server": "4.1.*",
        "doctrine/doctrine-migrations-bundle": "^3.0"
    },
    "require-dev": {
        "behat/behat": "3.4.*",
        "behat/gherkin": "4.6.0",
        "behat/mink": "dev-master#6d637f7af4816c26ad8a943da2e3f7eef1231bea",
        "behat/mink-extension": "2.3.*",
        "behat/mink-selenium2-driver": "1.3.1",
        "behat/symfony2-extension": "2.1.*",
        "guzzlehttp/guzzle": "^6.0.0",
        "nelmio/alice": "3.6.*",
        "theofidry/alice-data-fixtures": "1.0.*",
        "phpunit/phpunit": "7.5.*",
        "johnkary/phpunit-speedtrap": "3.0.*",
        "mybuilder/phpunit-accelerator": "dev-master",
        "squizlabs/php_codesniffer": "3.5.*",
        "phpmd/phpmd": "2.6.*",
        "sebastian/phpcpd": "4.0.*",
        "phpunit/phpcov": "5.0.*",
        "symfony/phpunit-bridge": "4.4.*",
        "friendsofphp/php-cs-fixer": "2.16.*",
        "oro/twig-inspector": "1.0.*"
    },
    "config": {
        "component-dir": "public/bundles/components",
        "bin-dir": "bin",
        "fxp-asset": {
            "enabled": false
        }
    },
    "scripts": {
        "post-install-cmd": [
            "@build-parameters",
            "@set-permissions",
            "@install-assets",
            "@set-assets-version"
        ],
        "post-update-cmd": [
            "@build-parameters",
            "@set-permissions",
            "@update-assets",
            "@set-assets-version"
        ],
        "build-parameters": [
            "Incenteev\ParameterHandler\ScriptHandler::buildParameters"
        ],
        "set-permissions": [
            "Oro\Bundle\InstallerBundle\Composer\ScriptHandler::setPermissions"
        ],
        "install-assets": [
            "Oro\Bundle\InstallerBundle\Composer\ScriptHandler::installAssets"
        ],
        "update-assets": [
            "Oro\Bundle\InstallerBundle\Composer\ScriptHandler::updateAssets"
        ],
        "set-assets-version": [
            "Oro\Bundle\InstallerBundle\Composer\ScriptHandler::setAssetsVersion"
        ],
        "set-parameters": [
            "Oro\Bundle\InstallerBundle\Composer\ParametersHandler::set"
        ]
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "extra": {
        "symfony": {
            "require": "4.4.*"
        },
        "symfony-web-dir": "public",
        "symfony-var-dir": "var",
        "symfony-bin-dir": "bin",
        "symfony-tests-dir": "tests",
        "incenteev-parameters": {
            "file": "config/parameters.yml"
        }
    }
}

尝试安装包,这样它就会添加到您的 composer.json 文件中。

composer install symfony/process

以下部分将导致安装正确的版本

"extra": {
        "symfony": {
            "require": "4.4.*"
        },

一旦你运行命令,包应该添加如下:

"symfony/process": "4.4.*"

如果不是,请将其更改为该版本号,然后运行

composer update symfony/process

最后我认为将 composer 安装在与 Web 应用程序相同的文件夹下似乎不是一个好习惯。此外,Platform.sh 似乎不使用 composer 二进制文件。

所以,我更改了 .platform.app.yaml 中的构建阶段,以避免 Platform.sh 安装 Composer 并使用自定义方式来完成它:

# .platform.app.yaml
hooks:
  build: |
    set -e
    cd $PLATFORM_APP_DIR

    # install Composer
    chmod +x composer-install.sh
    ./composer-install.sh

# composer-install.sh

#!/bin/sh

EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
    >&2 echo 'ERROR: Invalid installer checksum'
    rm composer-setup.php
    exit 1
fi

php composer-setup.php --1 --quiet
RESULT=$?
rm composer-setup.php
>&1 echo 'Composer successfully installed'
exit $RESULT