【问题标题】:Guzzle and Symfony 3: Unresolved base url breaks composer installGuzzle 和 Symfony 3:未解析的基本 url 破坏了 composer install
【发布时间】:2017-01-25 21:43:33
【问题描述】:

在我的 Symfony 3 应用程序中,我使用服务从 rest api 获取数据。

在此服务中,我正在注入“会话”和一个字符串,代表我的 rest api 的基本 url。

public function __construct(Session $session, $magentoRestUrl)
{
    $this->session  = $session;
    $this->client   = new \GuzzleHttp\Client([
        'base_uri' => $magentoRestUrl, // http://domain.com/rest/V1/
        'timeout'  => 2.0,
    ]);

    $this->cache = new ApcuAdapter();

    $this->groupedIngredients = [];
}

到目前为止,一切都在我的本地计算机上按预期运行。但是现在,在使用尚不存在的$magentoRestUrl 的部署过程中,运行composer install --no-dev 时出现此错误:

...
Writing lock file
Generating autoload files

[GuzzleHttp\Exception\ConnectException]                                                                               
cURL error 6: Could not resolve host: domain.com (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)  

Build step 'Execute shell' marked build as failure
Finished: FAILURE

我的问题是:为什么composer install 触发guzzle 来解决$magentoRestUrl?是不是因为在服务类的构造函数中?

这是我的 composer.json:

{
"name": "alex/symfony",
"license": "proprietary",
"type": "project",
"autoload": {
    "psr-4": {
        "": "src/"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"require": {
    "php": ">=5.5.9",
    "symfony/symfony": "3.1.*",
    "doctrine/orm": "^2.5",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/doctrine-cache-bundle": "^1.2",
    "symfony/swiftmailer-bundle": "^2.3",
    "symfony/monolog-bundle": "^2.8",
    "sensio/distribution-bundle": "^5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "^2.0",
    "symfony/assetic-bundle": "^2.8",
    "leafo/scssphp": "^0.6.3",
    "guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
    "sensio/generator-bundle": "^3.0",
    "symfony/phpunit-bridge": "^3.0"
},
"scripts": {
    "post-install-cmd": [
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ],
    "post-update-cmd": [
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ]
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-bin-dir": "bin",
    "symfony-var-dir": "var",
    "symfony-web-dir": "web",
    "symfony-tests-dir": "tests",
    "symfony-assets-install": "relative"
}

【问题讨论】:

    标签: php composer-php symfony guzzle


    【解决方案1】:

    Symfony 框架使用来自 composer.jsonpost-install-cmdpost-update-cmd 脚本,它们被 Composer 自动调用以初始化缓存、创建其 bootstrap.php.cache 等等。

    我认为其中一个在内部必须与依赖注入器一起使用,并且其中一个依赖项还需要解析引发此错误的服务(这取决于您的服务配置)。

    【讨论】:

    猜你喜欢
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 2020-08-16
    相关资源
    最近更新 更多