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?
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.