phlak/semver
phlak/semver is a lightweight PHP semantic versioning library for parsing, comparing, and manipulating version strings. Check constraints, bump major/minor/patch, and sort versions with a clean API—ideal for release tooling and dependency checks.
Install via Composer:
composer require phlak/semver
Start by using the Semver class to parse, compare, and manipulate semantic versions:
use Phlak\Semver;
$version = Semver::make('1.2.3');
echo $version->major; // 1
echo $version->minor; // 2
echo $version->patch; // 3
The most common first use case: validate and compare versions (e.g., for dependency checks):
$target = Semver::make('2.0.0');
$current = Semver::make('1.9.5');
if ($current->isLessThan($target)) {
// Require upgrade
}
$v = Semver::make('1.2.3-beta.1');
$v->bumpPatch(); // → 1.2.4
$v->bumpMinor(); // → 1.3.0
$v->bumpMajor(); // → 2.0.0
Semver::satisfies('1.5.2', '>=1.0.0 <2.0.0'); // true
$from = Semver::make('1.0.0');
$to = Semver::make('1.2.3');
echo $to->type(); // 'minor' (or 'major', 'patch')
Semver::parse() with strict mode to reject non-compliant versions.-alpha, +build.123) are preserved and respected in comparisons. 1.0.0-alpha < 1.0.0, but 1.0.0+build == 1.0.0 in equality checks unless using isIdentical().Semver::make() over parse() for safer parsing—make() throws InvalidVersionException on malformed strings.01.2.3)—they are treated as invalid by strict semver and will fail parsing.Semver::compare() with custom callbacks, or extend the class for domain-specific rules (e.g., enterprise versioning).Semver objects—parsing is cheap, but avoid redundant calls in tight loops.How can I help you explore Laravel packages today?