Documentation

VersionParser extends VersionParser
in package

Version parser.

Table of Contents

$constraints  : mixed
$modifierRegex  : string
Regex to match pre-release data (sort of).
$stabilities  : array<string|int, mixed>
isUpgrade()  : bool
normalize()  : string
Normalizes a version string to be able to perform comparisons on it.
normalizeBranch()  : string
Normalizes a branch name to be able to perform comparisons on it.
normalizeStability()  : string
parseConstraints()  : ConstraintInterface
Parses a constraint string into MultiConstraint and/or Constraint objects.
parseNameVersionPairs()  : array<string|int, array<string|int, mixed>>
Parses an array of strings representing package/version pairs.
parseNumericAliasPrefix()  : string|false
Extract numeric prefix from alias, if it is in numeric format, suitable for version comparison.
parseStability()  : string
Returns the stability of a version.
expandStability()  : string
Expand shorthand stability string to long version.
manipulateVersionString()  : string
Increment, decrement, or simply pad a version number.
parseConstraint()  : array<string|int, mixed>

Properties

$modifierRegex

Regex to match pre-release data (sort of).

private static string $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)((?:[.-]?\d+)*+)?)?([.-]?dev)?'

Due to backwards compatibility:

  • Instead of enforcing hyphen, an underscore, dot or nothing at all are also accepted.

  • Only stabilities as recognized by Composer are allowed to precede a numerical identifier.

  • Numerical-only pre-release identifiers are not supported, see tests.

                   |--------------|
    

[major].[minor].[patch] -[pre-release] +[build-metadata]

$stabilities

private static array<string|int, mixed> $stabilities = array('stable', 'RC', 'beta', 'alpha', 'dev')

Methods

isUpgrade()

public static isUpgrade(mixed $normalizedFrom, mixed $normalizedTo) : bool
Parameters
$normalizedFrom : mixed
$normalizedTo : mixed
Return values
bool

normalize()

Normalizes a version string to be able to perform comparisons on it.

public normalize(string $version[, string $fullVersion = null ]) : string
Parameters
$version : string
$fullVersion : string = null

optional complete version string to give more context

Tags
throws
UnexpectedValueException
Return values
string

normalizeBranch()

Normalizes a branch name to be able to perform comparisons on it.

public normalizeBranch(string $name) : string
Parameters
$name : string
Return values
string

normalizeStability()

public static normalizeStability(string $stability) : string
Parameters
$stability : string
Return values
string

parseNameVersionPairs()

Parses an array of strings representing package/version pairs.

public parseNameVersionPairs(array<string|int, mixed> $pairs) : array<string|int, array<string|int, mixed>>

The parsing results in an array of arrays, each of which contain a 'name' key with value and optionally a 'version' key with value.

Parameters
$pairs : array<string|int, mixed>

a set of package/version pairs separated by ":", "=" or " "

Return values
array<string|int, array<string|int, mixed>>

array of arrays containing a name and (if provided) a version

parseNumericAliasPrefix()

Extract numeric prefix from alias, if it is in numeric format, suitable for version comparison.

public parseNumericAliasPrefix(string $branch) : string|false
Parameters
$branch : string

Branch name (e.g. 2.1.x-dev)

Return values
string|false

Numeric prefix if present (e.g. 2.1.) or false

parseStability()

Returns the stability of a version.

public static parseStability(string $version) : string
Parameters
$version : string
Return values
string

expandStability()

Expand shorthand stability string to long version.

private expandStability(string $stability) : string
Parameters
$stability : string
Return values
string

manipulateVersionString()

Increment, decrement, or simply pad a version number.

private manipulateVersionString(array<string|int, mixed> $matches, int $position, int $increment[, string $pad = '0' ]) : string

Support function for

Parameters
$matches : array<string|int, mixed>

Array with version parts in array indexes 1,2,3,4

$position : int

1,2,3,4 - which segment of the version to increment/decrement

$increment : int
$pad : string = '0'

The string to pad version parts after $position

Return values
string

The new version

parseConstraint()

private parseConstraint(string $constraint) : array<string|int, mixed>
Parameters
$constraint : string
Tags
throws
UnexpectedValueException
Return values
array<string|int, mixed>

Search results