2017-09-25 35 views
0

我有以下composer.json文件:如何覆蓋由packagist.org上託管的composer.json定義的必需版本?

{ 
    "require": { 
    "guzzlehttp/guzzle": "^5.3" 
    }, 
    "require-dev": { 
    "aeris/guzzle-http-mock": ">=1.1.5" 
    } 
} 

,我想迫使aeris/guzzle-http-mock package使用不同版本的guzzlehttp/guzzle(如5.3.1),但它似乎要求讀取來自composer.json文件託管在packagist.org。是否有任何解決方法來覆蓋這些要求?

所以不是:

"guzzlehttp/guzzle": "~5.0.0" 

我想設置:

"guzzlehttp/guzzle": "^5.3" 
只改變我的地方 composer.json文件

理想。

目前該命令將顯示衝突錯誤:

$ composer install --prefer-source -vvv 
Reading ./composer.json 
Loading config file ./composer.json 
... 
Reading ~/.composer/cache/repo/https---packagist.org/provider-aeris$guzzle-http-mock.json from cache 
Resolving dependencies through SAT 
Dependency resolution completed in 0.000 seconds 
Reading ~/.composer/cache/repo/https---packagist.org/provider-guzzlehttp$guzzle.json from cache 
Your requirements could not be resolved to an installable set of packages. 

    Problem 1 
    - Installation request for aeris/guzzle-http-mock >=1.1.5 -> satisfiable by aeris/guzzle-http-mock[1.1.5]. 
    - aeris/guzzle-http-mock 1.1.5 requires guzzlehttp/guzzle ~5.0.0 -> satisfiable by guzzlehttp/guzzle[5.0.0, 5.0.1, 5.0.2, 5.0.3] but these conflict with your requirements or minimum-stability. 

回答

0

有使用replace property一種變通方法,旨在取代定的包,所以其他的包不會下載它。例如:

{ 
    "require": { 
    "aeris/guzzle-http-mock": ">=1.1.5" 
    }, 
    "replace": { 
    "guzzlehttp/guzzle": "~5.0.0" 
    }, 
    "minimum-stability": "dev", 
    "prefer-stable": true 
} 

將忽略guzzlehttp/guzzle依賴性,它不會被下載,但是正確的版本需要單獨或作爲包的一部分而提供。

例如,所需的存儲庫可以手動加入克隆:

"repositories": [ 
    { 
    "type": "vcs", 
    "url": "https://github.com/guzzle/guzzle.git" 
    } 
] 

另一個想法是使用inline aliases像:

"guzzlehttp/guzzle": "dev-5.3.0 as 5.0.3" 

,但它不工作無論如何,經過這種方式測試後,但也許有一種方法。


相關GitHub上線:How to replace the 3rd party dependency?