最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I require either an extension or a package with Composer? - Stack Overflow

programmeradmin3浏览0评论

I have a tool that requires the PHP intl extension, but if that is not present on the system, it can also work with symfony/intl (drawback is that then it's only English). So currently I have the following in composer.json:

{
    "require": {
        "symfony/intl": "*"
    },
    "suggest": {
        "ext-intl": ""
    }
}

This works, but the drawback is that symfony/intl gets installed whether it's needed or not. Ideally, I would like composer to check if ext-intl is installed and only if it isn't, symfony/intl should be installed.

Is there any way to do this? If researched a bit, and it seems for either/or requirements provide and "virtual packages" are recommended, but I don't think that would work for extensions, right?

I have a tool that requires the PHP intl extension, but if that is not present on the system, it can also work with symfony/intl (drawback is that then it's only English). So currently I have the following in composer.json:

{
    "require": {
        "symfony/intl": "*"
    },
    "suggest": {
        "ext-intl": ""
    }
}

This works, but the drawback is that symfony/intl gets installed whether it's needed or not. Ideally, I would like composer to check if ext-intl is installed and only if it isn't, symfony/intl should be installed.

Is there any way to do this? If researched a bit, and it seems for either/or requirements provide and "virtual packages" are recommended, but I don't think that would work for extensions, right?

Share Improve this question edited Feb 17 at 13:03 yivi 47.5k18 gold badges130 silver badges153 bronze badges asked Feb 14 at 14:01 user2792352user2792352 1611 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

No, there is no way to do that.

Things like this have been requested many times, and rejected.

If a package were to be a valid alternative for an extension, it could say so by using the provide keyword, as with any other virtual package.

You should probably suggest both things, and add runtime checks. The intl extension and the Symfony Intl component have different APIs anyway, so you'd have to check at runtime which to use, if you are using one as an alternative for the other.

发布评论

评论列表(0)

  1. 暂无评论