VersionParser
in package
Version parser.
Tags
Table of Contents
- $modifierRegex : string
- Regex to match pre-release data (sort of).
- $stabilitiesRegex : string
- 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.
- normalizeDefaultBranch() : string
- Normalizes a default branch name (i.e. master on git) to 9999999-dev.
- normalizeStability() : string
- parseConstraints() : ConstraintInterface
- Parses a constraint string into MultiConstraint and/or Constraint objects.
- 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|null
- 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]
$stabilitiesRegex
private
static string
$stabilitiesRegex
= 'stable|RC|beta|alpha|dev'
Methods
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
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 —normalizeDefaultBranch()
Normalizes a default branch name (i.e. master on git) to 9999999-dev.
public
normalizeDefaultBranch(string $name) : string
Parameters
- $name : string
Return values
string —normalizeStability()
public
static normalizeStability(string $stability) : string
Parameters
- $stability : string
Return values
string —parseConstraints()
Parses a constraint string into MultiConstraint and/or Constraint objects.
public
parseConstraints(string $constraints) : ConstraintInterface
Parameters
- $constraints : string
Return values
ConstraintInterface —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|null
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
Tags
Return values
string|null —The new version
parseConstraint()
private
parseConstraint(string $constraint) : array<string|int, mixed>
Parameters
- $constraint : string