Closed reedy closed 8 years ago
I think you will want to use Composer\Semver\Semver::satisfies()
.
The Comparator
class does not resolve version constraints, it uses raw versions only.
Looks to do the job to me. Thanks! 👍
> var_dump( Composer\Semver\Semver::satisfies( '1.6.1', '~1.6' ) );
/var/www/wiki/mediawiki/core/maintenance/eval.php(78) : eval()'d code:1:
bool(true)
> var_dump( Composer\Semver\Semver::satisfies( '1.7.1', '~1.6' ) );
/var/www/wiki/mediawiki/core/maintenance/eval.php(78) : eval()'d code:1:
bool(true)
> var_dump( Composer\Semver\Semver::satisfies( '1.5.1', '~1.6' ) );
/var/www/wiki/mediawiki/core/maintenance/eval.php(78) : eval()'d code:1:
bool(false)
The point to understand is that ~1.6
is not a version. It is a version constraint.
Bit of a support request here.
In MediaWiki, we're currently doing if version a !== version b, complain. Where one version is the one defined in composer.json file, and the other is the version of the dependency.
The downstream issue I filed is https://phabricator.wikimedia.org/T141225
The problem is that 1.6.1 does not equal ~1.6
I thought there'd be something we could use in the semver library, but I feel I'm coming up short, without looking for special characters, and doing different sorts of comparisons. What I hoped might work, would be something like the below, swapping !== for ! equalsTo, but it doesn't.
Am I just being stupid, and as such, is there a way to get it to do what I want? Basically, a version comparison, where one version may or may not have next significant release operators etc
Thanks in advance!