Skip to content

Getting Started

SemVer is a complete implementation of Semantic Versioning 2.0.0 for PHP, providing parsing, comparison, constraints, and version operations with full Laravel integration.

Requires PHP 8.4+

Terminal window
composer require cline/semver

The package auto-registers with Laravel via package discovery.

use Cline\SemVer\Version;
use Cline\SemVer\Constraint;
// Parse a version string
$version = Version::parse('2.1.0-beta.1+build.456');
echo $version->major; // 2
echo $version->minor; // 1
echo $version->patch; // 0
echo $version->preRelease; // beta.1
echo $version->build; // build.456
// Check constraints
$constraint = Constraint::parse('^2.0.0');
$constraint->isSatisfiedBy($version); // true
// Compare versions
$v1 = Version::parse('1.0.0');
$v2 = Version::parse('2.0.0');
$v1->lessThan($v2); // true
use Cline\SemVer\Facades\SemVer;
// Parse and validate
$version = SemVer::parse('1.2.3');
$isValid = SemVer::valid('1.2.3'); // true
// Compare versions
SemVer::gt('2.0.0', '1.0.0'); // true
SemVer::lt('1.0.0', '2.0.0'); // true
SemVer::eq('1.0.0', '1.0.0'); // true
// Check constraints
SemVer::satisfies('1.5.0', '^1.0.0'); // true
// Increment versions
$next = SemVer::incMajor('1.2.3'); // 2.0.0
$next = SemVer::incMinor('1.2.3'); // 1.3.0
$next = SemVer::incPatch('1.2.3'); // 1.2.4
ClassPurpose
VersionImmutable version representation with parsing and comparison
ConstraintVersion constraint matching (^, ~, ranges, wildcards)
VersionCollectionCollection with filtering and sorting
PreReleasePre-release identifier handling
BuildBuild metadata handling
SemVerManagerUnified API for all operations

This package fully implements the SemVer 2.0.0 specification:

  • Version Format: MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]
  • Pre-release Precedence: Numeric identifiers compare numerically; alphanumeric compare lexically
  • Build Metadata: Ignored in version precedence comparisons
  • Leading Zeros: Not allowed in numeric version components