Skip to content
docs

SemanticVersion

Immutable value object for semantic versioning (semver.org). Supports: - Parsing: SemanticVersion::parse('1.2.3-beta.1+build.42') - Comparison: $v1->greaterThan($v2), $v1->equals($v2) - Constraints: $v->satisfies('^2.0'), $v->satisfies('>=1.5 <3.0') - Incrementing: $v->incrementMajor(), $v->incrementMinor(), $v->incrementPatch()

SemanticVersion::__construct()

public function __construct(int $major, int $minor, int $patch, ?string $preRelease = null, ?string $build = null):

Parameters

Parámetros de __construct()
NombreTipoDescripción
$majorint
$minorint
$patchint
$preRelease?string
$build?string

SemanticVersion::parse()

public static function parse(string $version): self

Parse a version string. Accepts: "1.2.3", "v1.2.3", "1.2.3-beta", "1.2.3-beta.1+build.42", "1.2", "1"

Parameters

Parámetros de parse()
NombreTipoDescripción
$versionstring

Throws

\InvalidArgumentException If the version string is not valid semver

SemanticVersion::tryParse()

public static function tryParse(string $version): ?self

Try to parse a version string, return null on failure instead of throwing.

Parameters

Parámetros de tryParse()
NombreTipoDescripción
$versionstring

SemanticVersion::satisfies()

public function satisfies(string $constraint): bool

Check if this version satisfies a constraint string. Supported constraint formats: "^1.2.3" → >=1.2.3 <2.0.0 (caret — compatible with) "~1.2.3" → >=1.2.3 <1.3.0 (tilde — patch-level changes) ">=1.0" → greater or equal ">1.0" → strictly greater "<=2.0" → less or equal "<2.0" → strictly less "1.2.3" → exact match ">=1.0 <3.0" → range (space-separated AND) "*" → matches anything

Parameters

Parámetros de satisfies()
NombreTipoDescripción
$constraintstring

SemanticVersion::greaterThan()

public function greaterThan(self $other): bool

Whether this version sorts strictly after $other.

Parameters

Parámetros de greaterThan()
NombreTipoDescripción
$otherself

SemanticVersion::greaterThanOrEqual()

public function greaterThanOrEqual(self $other): bool

Whether this version sorts after or equal to $other.

Parameters

Parámetros de greaterThanOrEqual()
NombreTipoDescripción
$otherself

SemanticVersion::lessThan()

public function lessThan(self $other): bool

Whether this version sorts strictly before $other.

Parameters

Parámetros de lessThan()
NombreTipoDescripción
$otherself

SemanticVersion::lessThanOrEqual()

public function lessThanOrEqual(self $other): bool

Whether this version sorts before or equal to $other.

Parameters

Parámetros de lessThanOrEqual()
NombreTipoDescripción
$otherself

SemanticVersion::equals()

public function equals(self $other): bool

Whether this version has the same precedence as $other (build metadata is ignored, per semver).

Parameters

Parámetros de equals()
NombreTipoDescripción
$otherself

SemanticVersion::compareTo()

public function compareTo(self $other): int

Compare two versions.

Parameters

Parámetros de compareTo()
NombreTipoDescripción
$otherself

Returns

-1 if $this < $other, 0 if equal, 1 if $this > $other

SemanticVersion::isStable()

public function isStable(): bool

Whether this is a stable release, i.e. it carries no pre-release identifier.

SemanticVersion::incrementMajor()

public function incrementMajor(): self

Returns a new version with major incremented and minor/patch reset to 0 (pre-release/build dropped).

SemanticVersion::incrementMinor()

public function incrementMinor(): self

Returns a new version with minor incremented, patch reset to 0, major unchanged (pre-release/build dropped).

SemanticVersion::incrementPatch()

public function incrementPatch(): self

Returns a new version with patch incremented, major/minor unchanged (pre-release/build dropped).

SemanticVersion::__toString()

public function __toString(): string