composer/semver
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The composer/semver is a Semantic Versioning (Semver) library that offers utilities for version constraint parsing and validation. It was originally a part of the composer/composer but is now a stand-alone library which developers can use independently. Utilizing composer/semver can prove useful for better versioning management in coding projects by providing efficient version comparison functions.
composer/semver has a straightforward installation process. All you need is a PHP environment (version 5.3.2 and above recommended), and you can use the Composer dependency manager to install it with this command at your terminal: composer require composer/semver
.
To make the best use of this package, here are some code examples for basic usage:
For comparing versions, you can utilize the Composer\Semver\Comparator
class like this:
use Composer\Semver\Comparator;
Comparator::greaterThan('1.25.0', '1.24.0'); // Returns true if 1.25.0 > 1.24.0
The Semver class provides various methods like satisfies(), satisfiedBy(), sort(), rsort()
, etc. which can be employed according to your requirements.
For dealing with complex constraints or reading version intervals from a constraint, the Composer\Semver\Intervals
class has many useful methods:
use Composer\Semver\Intervals;
// Checks whether $candidate is a subset of $constraint
Intervals::isSubsetOf(ConstraintInterface $candidate, ConstraintInterface $constraint);
For a deeper understanding of how versions are compared and how to make the most of composer/semver, referring to the official documentation can prove beneficial. You will find detailed usage guides and examples in the composer/semver repository on GitHub. For complete information on version comparison as per composer/semver, you can refer to the Versions article in the documentation section on the getcomposer.org website.