Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork74
Semantic versioning utilities with the addition of version constraints parsing and checking.
License
composer/semver
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Version comparison library that offers utilities, version constraint parsing and validation.
It follows semver (semantic versioning) where possible but is also constrained byversion_compare and backwards compatibility and as such cannot implement semver strictly.
Originally written as part ofcomposer/composer,now extracted and made available as a stand-alone library.
Install the latest version with:
composer require composer/semver
- PHP 5.3.2 is required but using the latest version of PHP is highly recommended.
For details on how versions are compared, refer to theVersionsarticle in the documentation section of thegetcomposer.org website.
TheComposer\Semver\VersionParserclass provides the following methods for parsing, normalizing and validating versions and constraints.
Numeric versions are normalized to a 4 component versions (e.g.1.2.3 is normalized to1.2.3.0)for internal consistency and compatibility withversion_compare. Normalized versions are used forconstraints internally but should not be shown to end users.
For versions:
- isValid($version)
- normalize($version, $fullVersion = null)
- normalizeBranch($name)
- normalizeDefaultBranch($name)
For constraints:
- parseConstraints($constraints)
For stabilities:
- parseStability($version)
- normalizeStability($stability)
TheComposer\Semver\Comparator class provides the following methods for comparing versions:
- greaterThan($v1, $v2)
- greaterThanOrEqualTo($v1, $v2)
- lessThan($v1, $v2)
- lessThanOrEqualTo($v1, $v2)
- equalTo($v1, $v2)
- notEqualTo($v1, $v2)
Each function takes two version strings as arguments and returns a boolean. For example:
useComposer\Semver\Comparator;Comparator::greaterThan('1.25.0','1.24.0');// 1.25.0 > 1.24.0
TheComposer\Semver\Semver class provides the following methods:
- satisfies($version, $constraints)
- satisfiedBy(array $versions, $constraint)
- sort($versions)
- rsort($versions)
TheComposer\Semver\Intervals static class providesa few utilities to work with complex constraints or read version intervals from a constraint:
useComposer\Semver\Intervals;// Checks whether $candidate is a subset of $constraintIntervals::isSubsetOf(ConstraintInterface$candidate, ConstraintInterface$constraint);// Checks whether $a and $b have any intersection, equivalent to $a->matches($b)Intervals::haveIntersections(ConstraintInterface$a, ConstraintInterface$b);// Optimizes a complex multi constraint by merging all intervals down to the smallest// possible multi constraint. The drawbacks are this is not very fast, and the resulting// multi constraint will have no human readable prettyConstraint configured on itIntervals::compactConstraint(ConstraintInterface$constraint);// Creates an array of numeric intervals and branch constraints representing a given constraintIntervals::get(ConstraintInterface$constraint);// Clears the memoization cache when you are done processing constraintsIntervals::clear()
See the class docblocks for more details.
composer/semver is licensed under the MIT License, see the LICENSE file for details.
About
Semantic versioning utilities with the addition of version constraints parsing and checking.
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.