I have a two version of my package: for php7 and for php5. Is it possible to make composer determine when installing the package which version of php the user has, and depending
TL;DR: Yes.
By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config
section of composer.json, for example:
"config": {
"vendor-dir": "vendor",
"platform": {
"php": "5.6"
}
}
When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:
"require": {
"php": ">=7.2.0",
}
So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package
with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.