Composer Dependence on a Specified PHP Version

Is it possible to tell the composer to establish dependency only when using the specified versions of PHP?

Reason: my library uses the password_hash function, which is available in version 5.5+, and there is an ircmaxell / password-compat compatibility library for PHP 5.4. However, installing this library on PHP 5.5+ is completely pointless. So, is it possible to tell the composer to set ircmaxell / password-compat only when launched in versions <5.5?

The story, to make the question clearer - I want to tell the composer:

IF php version < 5.5: install ircmaxell/password-compat ELSE: skip ircmaxell/password-compat 

Thanks in advance.

PS Please post only direct answers on how to do this, and not workarounds or recommendations to reduce support 5.4. I can also come up with them, I'm looking for a smart solution here :)

+6
source share
2 answers

Short answer: "This is not possible."

Dependence is not massive. Why not just install it anyway? If you are on PHP 5.5, the built-in password functions will still be used.

You can also make password-compat an optional dependency ( suggests ). The problem is that the developer must install it along with your application.

Finally, you can make a secondary virtual package. Suppose your package is called "Acme". It would be possible to create an additional package "Acme-php54", which depends on both the password and your main project. This keeps the dependency outside of your project, but I would say that the easiest thing is to just install it while you intend to support PHP 5.4, and just drop PHP 5.4 after a while, when it will be EOL.

+3
source

Yes it is possible.

Consider one branch, for example. 1.x for legacy php versions like

 { "name": "some/library", "version": "1.0.0", "require": { "ircmaxell/password-compat": "*" } } 

and 2.x for 5.5 +

 { "name": "some/library", "version": "2.0.0", "require": { "php": ">=5.5" } } 

Thus, the requirements for the free version, i.e. some/library:* will be allowed to the corresponding versions.

Another way is to tell users to add

 "replace": { "ircmaxell/password-compat": "*" } 

independently, if necessary.

Please note that some users (including me) can change their php interpreter on the fly and will not be too happy to debug such automatic problems.

+2
source

All Articles