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
| Nombre | Tipo | Descripción |
|---|---|---|
| $major | int | |
| $minor | int | |
| $patch | int | |
| $preRelease | ?string | |
| $build | ?string |
SemanticVersion::parse()
public static function parse(string $version): selfParse 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
| Nombre | Tipo | Descripción |
|---|---|---|
| $version | string |
Throws
\InvalidArgumentException If the version string is not valid semver
SemanticVersion::tryParse()
public static function tryParse(string $version): ?selfTry to parse a version string, return null on failure instead of throwing.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $version | string |
SemanticVersion::satisfies()
public function satisfies(string $constraint): boolCheck 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
| Nombre | Tipo | Descripción |
|---|---|---|
| $constraint | string |
SemanticVersion::greaterThan()
public function greaterThan(self $other): boolWhether this version sorts strictly after $other.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $other | self |
SemanticVersion::greaterThanOrEqual()
public function greaterThanOrEqual(self $other): boolWhether this version sorts after or equal to $other.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $other | self |
SemanticVersion::lessThan()
public function lessThan(self $other): boolWhether this version sorts strictly before $other.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $other | self |
SemanticVersion::lessThanOrEqual()
public function lessThanOrEqual(self $other): boolWhether this version sorts before or equal to $other.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $other | self |
SemanticVersion::equals()
public function equals(self $other): boolWhether this version has the same precedence as $other (build metadata is ignored, per semver).
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $other | self |
SemanticVersion::compareTo()
public function compareTo(self $other): intCompare two versions.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $other | self |
Returns
-1 if $this < $other, 0 if equal, 1 if $this > $other
SemanticVersion::isStable()
public function isStable(): boolWhether this is a stable release, i.e. it carries no pre-release identifier.
SemanticVersion::incrementMajor()
public function incrementMajor(): selfReturns a new version with major incremented and minor/patch reset to 0 (pre-release/build dropped).
SemanticVersion::incrementMinor()
public function incrementMinor(): selfReturns a new version with minor incremented, patch reset to 0, major unchanged (pre-release/build dropped).
SemanticVersion::incrementPatch()
public function incrementPatch(): selfReturns a new version with patch incremented, major/minor unchanged (pre-release/build dropped).
SemanticVersion::__toString()
public function __toString(): string