How to always use ignore-platform-reqs flag when running composer?

▼魔方 西西 提交于 2019-12-13 12:25:00

问题


On my local machine, I have php v7.0.3. A project of mine has a dependency on php v5.5.

So as expected, a simple run of composer install crashes:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ~5.5 but your PHP version (7.0.3) does not satisfy that requirement.

I know I can ignore the platform via:

composer install --ignore-platform-reqs

yet I often forget to add the flag. Yet since the application runs inside a docker container, a mismatching php can install the dependencies just as fine.

So I am wondering if there is a way to make my local composer always assume --ignore-platform-reqs in order to not having to type it.

I like to avoid setting an alias and have it work on composer config level.


回答1:


It's recommended to fake php version, rather than ignore platform requirements. Add

"platform":{"php":"5.5"}

to your ~/.composer/config.json or use composer config -g -e to edit it.

An example of sufficient config to fake php version:

{
    "config": {
        "platform":{
            "php":"5.5"
        }
    }
}

It may have much more options though.




回答2:


You can add alias composer="composer --ignore-platform-reqs" to your .bash_profile but it will break commands that don't recognize this option (eg. composer outdated).

Personally I have:

alias composer="composer --ignore-platform-reqs"
alias composer_orig="/usr/local/bin/composer"

Because most of the time I want --ignore-platform-reqs, but still I can use composer_orig each time I see

[Symfony\Component\Console\Exception\RuntimeException]

The "--ignore-platform-reqs" option does not exist.



来源:https://stackoverflow.com/questions/35273522/how-to-always-use-ignore-platform-reqs-flag-when-running-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!