Versioneye is a good way to track dependencies, I enjoy using it, however I've run into an issue:
My repository is for php 5.4 and greater which means I must use phpunit ~4.8
Versioneye however says my dependency for phpunit is outdated because 5.1.* is the latest, but you cannot run phpunit 5 on anything less than php 5.6.
Is there a way to specify in composer or anywhere else that on php 5.4/5.5 phpunit 4.8 should be used and on php 5.6 phpunit 5.1.* should be used?
Or do I simply go into versioneye and tell it not to consider 5.1.17 at all? But then I have to constantly keep that up-to-date.
Thanks for your help in advance, here are the git repo and version eye links:
https://github.com/thephpeffect/TriggrPHP
https://www.versioneye.com/user/projects/56b3ba5e0a0ff5002c85ed7b?child=summary
If you set the PHP version in composer.json it should update only the dependency to versions that are admitted in PHP 5.4. This would prevent the outdated libraries message, and you shouldn't need to care anymore:
"config" : {
"platform": {
"php": "5.4"
}
}
But AFAIK there is no way of choosing the version depending on the installed PHP version.
I found that if I used
"phpunit/phpunit": "~4.8|~5.1"
it automatically detects that 5.1 is an option regardless of php version and shows dependencies as up-to-date.
Related
apparently composer is having problems understanding version definitions. after installing composer using the official guide here: https://getcomposer.org/download/ i tried stuff like composer install or composer update, but every command returns the following error message:
Could not parse version constraint >=7.4.*: Invalid version string "7.4.*"
php version: 7.4.28
composer version: 2.3.5
i did not set up composer for this project, i just want to add a library. usually i just download the php files directly as this is far more efficient, but someone decided this project needs to use composer and now we are in this mess.
does anyone know what the problem is?
Afaik just 7.4 works - and from my logical assumption this should also include 7.4.* ;)
Composer don't install the package with versions separated by logical OR.
First image. As expected, I got all 5.x versions.
"require": {
"illuminate/http": "^5"
},
Second image:
"require": {
"illuminate/http": "^5||^6"
},
I expect to get all 5.x versions and all 6.x versions, but always get the one latest version.
How to fix this?
You can't install multiple versions of the same package. Composer just doesn't support that, and it's unlikely that will change given it's mostly oriented towards php. You could try installing via bower, but I don't think it supports two versions at once either..
For more details https://getcomposer.org/doc/03-cli.md#require
Ok, I understood.
This is the fault of the composer.lock. Usually, you should not commit composer.lock to vcs if you are making a library.
Because then the version of the dependency of your library will be locked at the one specific version.
But usually library must be compatible with as many versions of the dependency as possible.
Also, you can't install one of compatible versions of the dependency if you already have installed one (even you delete composer.lock).
composer.lock force point version to the specific value, can't install one of compatible with other dependencies:
You already have some installed version, can't install another one. Even if your composer.json allows to install one of compatible versions.
So, I just delete /vendor and composer.lock and composer select one of the compatible versions itself.
Well, after running command composer outdated I can see there's newer version of phpdocumentor/type-resolver available. Installed version is 0.2.1 and the latest one is 0.3.0. Need to say that it was indirectly installed by component I use and not by me.
Problem is when I run composer update or composer update phpdocumentor/type-resolver it says "Nothing to install or update". Why and how to fix?
probably some dependency have fixed the package release you want to install. Try so the the output of the command to check who are using and at which version the package you listed:
composer why-not phpdocumentor/type-resolver 0.3.0
NB: in the current version of the documentation of composer the command is named prohibits, so in case this doesn't work try with:
composer prohibits phpdocumentor/type-resolver 0.3.0
Hope this help
You might have version constraints blocking the upgrade in your composer.json file. This is intended to prevent adding in breaking changes. In your example, the versions are pre-release (0.*), so versioning constraints even act on the miner version.
If you are confident there are no breaking changes or you are prepared to deal with them, edit your composer.json file. Change something like:
"phpdocumentor/type-resolver": "0.2.1",
to
"phpdocumentor/type-resolver": "^0.3",
Try composer upgrade again and test it out to make sure everything is ok.
I have put
"require": {
"php": ">=5.5",
"phpunit/phpunit": ">4,<6"
},
inside my composer.json file:
https://github.com/giorgiosironi/eris/blob/master/composer.json#L20
composer install however still accepts to be run on hhvm, as seen at:
https://travis-ci.org/giorgiosironi/eris/jobs/118241849
I thought requiring php meant I wanted a particular version of php, so hhvm was excluded. It seems instead that this choice means that if there is a php present, it must satisfy the version constraint, but if there is only hhvm it won't apply.
Is this what is happening? If so, how can I specify the package is incompatible with hhvm?
You can use the conflict option to say that your package conflicts with HHVM. This would look like
"conflict": {
"hhvm": "*"
}
which sets your package as conflicting with every version of HHVM.
HHVM emits the PHP_VERSION constants. I'm fairly sure that composer simply uses those constants to figure out the version here.
My understanding is that HHVM has increased their PHP_VERSION as they obtained feature parity with the associated vanilla php version.
Nope, if php is in the required array is MUST be installed and be at least the version specified. As #Evert stated HHVM provides a php version when queried.
Check this out for hhvm dependency: https://getcomposer.org/doc/02-libraries.md#platform-packages
I have a mix of different PHP versions running on my servers (max 5.3.5) and development machines (max 5.5.9).
Now I ran into the problem that I did a "composer update" to get the latest Version of some external Bundles.
My composer.json looks like
"require": {
"php": ">=5.3.3",
.....
},
I get some Bundles that required PHP 5.5. There is no problem on my dev machines; the problem occurs on the server.
Is it possibile to tell Composer to require a PHP version between 5.3.3 and 5.3.5? Or a max available Version?
I tried
"require": {
"php": ">=5.3.3, <=5.3.5",
.....
},
and
"require": {
"php": "<=5.3.5",
.....
},
but both didn't work out. I get a "The requested package php could not be found in any version, there may be a typo in the package name." Error.
Any Ideas?
Since the config parameter in composer.json is available. You could something like this:
{
"name": ".../...",
"config": {
"platform": {
"php": "5.3.5"
}
},
"require": {
...
}
}
https://getcomposer.org/doc/06-config.md#platform
I find it questionable to say the least that you are developing with the newest PHP available and are running production with a very outdated version. There will be plenty of possible problems arising from this, not only because of security patches that you would be missing, but more importantly because of PHP bug fixes that got introduced mostly in versions 5.3.9 and 5.3.23 that changes PHP behavior in some details pretty fundamentally. Not talking about the risk of accidentally using features of 5.4 or 5.5.
And there really is no way to make Composer deal with this situation. The PHP version that is used when running composer update determines the resolution of dependencies, being influenced by PHP version and installed PHP extensions.
You cannot define that a package should only be used for PHP versions between 5.3.3 and 5.3.5 if the PHP you are using for the update is not matching this version requirement. Because the used PHP version exceeds the upper version constraint, such a package is not eligible for fulfilling the version requirement, and Composer reports that no package has been found (not telling that it has seen the packages, but they had to be ignored because of the version constraint).
There are probably three obvious ways out:
Downgrade your development environment to the production version you are really using. If more than one is used: The oldest one. That way any requirements for PHP versions will be matched. Run composer update then, and you are done.
Upgrade your production environment. Needs no further explanation, but I have to mention that not only are you missing a lot of very nice PHP features, you are also missing a substantial performance increase, because PHP 5.5 is really that much faster than 5.3.
Add a "platform.php" configuration to either the global or project's composer.json. This will tell Composer to override the PHP version running Composer itself, and instead calculate the dependencies with that different PHP version. composer config -g platform.php 5.3.5 for global setting (will affect all further Composer runs), without -g for local setting (will only affect Composer operations in that project, in case you develop on more than one project with different production versions of PHP).
Remove your composer.lock and vendor directory.
Now place platform option to composer.json
"config": {
"platform": {
"php": "7.0"
}
},
and finally, run command composer install
Try this (remove comma):
"require": {
"php": ">=5.3.3 <=5.3.5",
.....
},
What about trying the tilde operator
Tilde Operator ~1.2 Very useful for projects that follow semantic versioning. ~1.2 is
equivalent to >=1.2,<2.0. For more details, read the next section
below.
Next Significant Release (Tilde Operator)#
The ~ operator is best explained by example:
~1.2 is equivalent to
=1.2,<2.0, while
~1.2.3 is equivalent
to >=1.2.3,<1.3. As you can see it is mostly useful for projects respecting semantic versioning. A common
usage would be to mark the minimum minor version you depend on, like ~1.2 (which allows anything up to, but not
including, 2.0). Since in theory there should be no backwards compatibility breaks until 2.0, that works well. Another way of looking at it is that using ~ specifies a minimum version, but allows the last digit specified to go up.
Note: Though 2.0-beta.1 is strictly before
2.0, a version constraint like
~1.2 would not install it. As
said above ~1.2 only means the
.2 can change but the
1. part is fixed.
Note: The ~ operator has an exception on its behavior for the major release number. This means for
example that ~1 is the same as
~1.0 as it will not allow the major number to increase trying to keep
backwards compatibility.
Is there any possibility to tell composer to require a PHP version
between 5.3.3 and 5.3.5?
Yes, there it is one:
Hyphenated Version Range ( - )
Inclusive set of versions. Partial
versions on the right include are completed with a wildcard. For
example 1.0 - 2.0 is equivalent to >=1.0.0 <2.1 as the 2.0 becomes
2.0.*. On the other hand 1.0.0 - 2.1.0 is equivalent to >=1.0.0 <=2.1.0.
Example: 1.0 - 2.0
https://getcomposer.org/doc/articles/versions.md#hyphenated-version-range-
or you may use composer.json like this:
{
"require": {
"guzzlehttp/guzzle": ">=5.3.4 <6"
}
}
- I personally prefer this way because it's much easier to read and remember IMHO.