Jump to content

How to install two packages of the same library in composer and have each run depending on the PHP version?


Recommended Posts

I need to implement T-Regx library - https://github.com/T-Regx/T-Regx - in a project that might be running in PHP 5.6 or PHP 7.1+, depending on which version the server has installed.

So, on PHP 5.6, I need to run package #1 and on PHP 7.1+ package #2. However, whenever I install the package it creates the directory /vendor/rawr/t-regx/ - I need to have something like /vendor/rawr/t-regx-5.6/ and /vendor/rawr/t-regx-7-1-plus/ and composer should trigger the needed one based on the PHP version. I need this because plenty of people still use PHP 5.6 and I can't just tell them to upgrade (it's not that simple). If I use a PHP 5.6 package and the user has PHP 8 installed, there will be errors shown that would annoy the user.

Any suggestions? I'm sure other users are having this issue.

If you install it on the target system with composer, then composer will install whichever version of the package is compatible automatically, just make sure you have your version constraint for the package setup correctly.

If you're trying to pre-package a release and want to make a 5.6 version and 7.1 version, you could have both version of PHP installed and run composer with the appropriate version.

That will not work because this is to be implemented in a WordPress plugin that is installed on various websites either having PHP 5.6 or PHP 7.1+. So, it needs to have both versions installed and detect which PHP version is used and load the package accordingly. This can be easily done in PHP, but when it comes to Composer, I need to implement this effectively and I'm out of ideas. The library they provide work well with Composer and they highly recommend it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.