Download the PHP package jeffpacks/semver without Composer
On this page you can find all versions of the php package jeffpacks/semver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeffpacks/semver
More information about jeffpacks/semver
Files in jeffpacks/semver
Package semver
Short Description A simple implementation of a SemVer 2.0.0 semi-compliant version number
License MIT
Homepage https://github.com/jeffpacks/semver
Informations about the package semver
About
The VersionNumber
class of this library represents a SemVer 2.0.0 semi-compliant version number. The class offers methods for querying the version number it represents as well as methods for comparison and manipulation.
The VersionRange
class represents a range a version number falls inside or outside of. It currently only offers caret range support.
Requirements
This library requires PHP 7.4/8.0 and jeffpacks/substractor.
Installing
Run composer require jeffpacks/semver
in your project's root directory and use \jeffpacks\semver\VersionNumber
in your PHP script/class.
If you don't want to use Composer or its classloader and have downloaded this library, you may use the built-in classloader instead:
Code examples
Semantic Versioning compliance
This library supports some formats that are not covered by SemVer 2.0.0, but lacks support for other esoteric formats that SemVer defines. The most important one is that while SemVer 2.0.0 defines the version core MAJOR.MINOR.PATCH, MINOR and PATCH are optional in this library. You may work with version numbers consisting of a MAJOR segment only or a MAJOR.MINOR format. Furthermore, the library also supports a fourth optional segment known as the AUX segment. Use it for whatever floats your boat.
This library does not yet support the flexible pre-release segment format specified in SemVer 2.0, but is currently limited to the following format (Backus–Naur form grammar):
In short, beta
, beta.1
, beta.25
etc are allowed pre-release segments, but not beta.0
, beta.1.13
etc.
Zero-major segment interpretation
A version number with a MAJOR segment set to 0
is interpreted by this library as a non-stable version, on par with an ALPHA or BETA version. Here are some of the allowed combinations:
- 0
- 0.0
- 0.0.0
- 0.0.0.0
- 0.0.0-alpha
- 0.0.0-alpha.1
Which of 0.0.0
and 0.0.0-alpha.1
is higher is not addressed by SemVer 2.0.0, so the rule of thumb for this library is that a version number without a pre-release segment (alpha.1
in this case) is always considered higher than a version number with a pre-release segment. In short, 0.0.0
> 0.0.0-beta.1
> 0.0.0-alpha.1
.
Comparison
This library provides methods for comparing version numbers of different version core formats. The comparison is done based on the following rules:
- the numeric value of the version number (e.g.
2.1
has a higher numeric value than1.3
) - the number of segments in the version core (e.g
1.2
is lower than1.2.0
) - the presence of a pre-release number (e.g.
1.2.3-beta
is lower than1.2.3-beta.1
)
Authors
License
MIT License