questocat / version-comparator
Compares two version number strings based on Semantic Versioning 2.0.0
Installs: 4 021
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.8
This package is auto-updated.
Last update: 2024-10-20 13:51:06 UTC
README
Compares two version number strings based on Semantic Versioning 2.0.0
Installation
Using Composer to add the package to your project's dependencies:
$ composer require questocat/version-comparator
Usage
Using compare method
$semVerManager = new SemVerManager(); $semVerManager->compare('2.9.0', '2.9.6', '<'); // true $semVerManager->compare('5.1.0', '5.1.0-alpha', '>'); // true $semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '<'); // false $semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '>'); // true $semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '!='); // true $semVerManager->compare('1.0.0-alpha.1', '1.0.0-alpha.beta', '<'); // true $semVerManager->compare('2.0.1-alpha-abc.2', '2.0.1-alpha-abc.1', '>'); // true $semVerManager->compare('1.0.0-alpha', '1.0.0-beta', '<'); // true $semVerManager->compare('0.0.0+0', '0.0.0+1', '='); // true $semVerManager->compare('1.0.0-alpha+001', '1.0.0+20130313144700', '<'); // true $semVerManager->compare('1.0.0-rc.1+build.1', '1.0.0-rc.1', '<'); // false $semVerManager->compare('1.0.0-rc.1+build.1', '1.0.0-rc.1', '='); // true $semVerManager->compare('1.0.0-rc.2+build.1', '1.0.0-rc.1', '<'); // fasle $semVerManager->compare('1.0.0-rc.2+build.1', '1.0.0-rc.1', '>='); // true
Other examples
$semVerManager->compare('1.0.0-alpha', '1.0.0-alpha.1', '<'); $semVerManager->compare('1.0.0-alpha.1', '1.0.0-alpha.beta', '<'); $semVerManager->compare('1.0.0-alpha.beta', '1.0.0-beta', '<'); $semVerManager->compare('1.0.0-beta', '1.0.0-beta.2', '<'); $semVerManager->compare('1.0.0-beta.2', '1.0.0-beta.11', '<'); $semVerManager->compare('1.0.0-beta.11', '1.0.0-rc.1', '<'); $semVerManager->compare('1.0.0-rc.1', '1.0.0', '<');
Conclusion
1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0- rc.1 < 1.0.0
Using compareTo method
$semVerManager = new SemVerManager('2.9.0'); $semVerManager->compareTo('2.9.6', '<'); // true $semVerManager->compareTo('2.8.9', '>'); // true $semVerManager->compareTo('2.8.9-alpha', '>'); // true
Reference
License
Licensed under the MIT license.