Index Documentation

Version
in package
implements Stringable, IComparable, IEquatable

A Semantic Versioning implementation. Following version 2.0.0 of the specification.

Tags
see
https://semver.org/spec/v2.0.0.html

Table of Contents

Interfaces

Stringable
IComparable
Provides an interface for comparison between objects. Allows for order/sorting instances.
IEquatable
Provides an interface for determining the value-equality of two objects.

Methods

__construct()  : Version
Constructor for Version.
__toString()  : string
compare()  : int
Compares this instance of Version with another.
empty()  : Version
Returns an empty Version instance.
equals()  : bool
Checks this instance of Version with another for equality.
getBuild()  : array<string|int, mixed>
Gets the split value of the build component.
getMajor()  : int
Gets the value of the major version component.
getMinor()  : int
Gets the value of the minor version component.
getPatch()  : int
Gets the value of the patch version component.
getPrerelease()  : array<string|int, mixed>
Gets the split value of the prerelease component.
incrementMajor()  : Version
Creates a new instance of Version with the major component incremented.
incrementMinor()  : Version
Creates a new instance of Version with the minor component incremented.
incrementPatch()  : Version
Creates a new instance of Version with the patch component incremented.
isPrerelease()  : bool
Tests if this Version instance represents a prerelease according to the SemVer spec.
parse()  : Version
Parses a version string.

Methods

__construct()

Constructor for Version.

public __construct(int $major[, int $minor = 0 ][, int $patch = 0 ][, string $prerelease = '' ][, string $build = '' ]) : Version
Parameters
$major : int

A positive integer indicating the major version.

$minor : int = 0

A positive integer indicating the minor version.

$patch : int = 0

A positive integer indicating the patch version.

$prerelease : string = ''

A dot separated string indicating prerelease information.

$build : string = ''

A dot separated string indicating build information.

Tags
throws
InvalidArgumentException

A negative integer was provided.

Return values
Version

__toString()

public __toString() : string
Return values
string

compare()

Compares this instance of Version with another.

public compare(mixed $other) : int

The build component is ignored and prerelease component is compared as per the SemVer spec.

Parameters
$other : mixed

Another instance of Version.

Return values
int

A value that indicates the relative order of the objects being compared. Less than zero for before, zero for same position, greater than zero for after.

empty()

Returns an empty Version instance.

public static empty() : Version
Return values
Version

Instance of Version with all values set to 0.

equals()

Checks this instance of Version with another for equality.

public equals(mixed $other) : bool

The build component is ignored, as per the SemVer spec.

Parameters
$other : mixed

Another instance of Version.

Return values
bool

true if the instances are equal, false if not.

getBuild()

Gets the split value of the build component.

public getBuild() : array<string|int, mixed>
Return values
array<string|int, mixed>

array contains the build parts.

getMajor()

Gets the value of the major version component.

public getMajor() : int
Return values
int

Major version component.

getMinor()

Gets the value of the minor version component.

public getMinor() : int
Return values
int

Minor version component.

getPatch()

Gets the value of the patch version component.

public getPatch() : int
Return values
int

Patch version component.

getPrerelease()

Gets the split value of the prerelease component.

public getPrerelease() : array<string|int, mixed>
Return values
array<string|int, mixed>

array containing the prerelease parts.

incrementMajor()

Creates a new instance of Version with the major component incremented.

public incrementMajor() : Version

This will implicitly drop prerelease and build info and reset the minor and patch component.

Return values
Version

the newly created instance of Version.

incrementMinor()

Creates a new instance of Version with the minor component incremented.

public incrementMinor() : Version

This will implicitly drop the prerelease and build info and reset the patch component.

Return values
Version

the newly created instance of Version.

incrementPatch()

Creates a new instance of Version with the patch component incremented.

public incrementPatch() : Version

This will implicitly drop the prerelease and build info.

Return values
Version

the newly created instance of Version.

isPrerelease()

Tests if this Version instance represents a prerelease according to the SemVer spec.

public isPrerelease() : bool
Return values
bool

true if the version indicates a prerelease, false if not.

parse()

Parses a version string.

public static parse(string $versionString) : Version

Parses a version string with a regex adapted from SemVer's documentation. Modified to allow an optional v prefix.

Parameters
$versionString : string

String containing a version number.

Tags
see
https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
throws
InvalidArgumentException

Provided string does not represent a valid version.

Return values
Version

An instance of Version representing the provided version string.


        
On this page

Search results