Documentation

VersionParser
in package

Version parser.

Tags
author

Jordi Boggiano j.boggiano@seld.be

Table of Contents

Properties

$modifierRegex  : string
Regex to match pre-release data (sort of).
$stabilitiesRegex  : string

Methods

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|null $fullVersion = null ]) : string
Parameters
$version : string
$fullVersion : string|null = 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

normalizeDefaultBranch()

Normalizes a default branch name (i.e. master on git) to 9999999-dev.

public normalizeDefaultBranch(string $name) : string
Parameters
$name : string
Tags
deprecated

No need to use this anymore in theory, Composer 2 does not normalize any branch names to 9999999-dev anymore

Return values
string

normalizeStability()

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

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
Tags
phpstan-return

'stable'|'RC'|'beta'|'alpha'|'dev'

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 = 0 ][, string $pad = '0' ]) : string|null

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 = 0
$pad : string = '0'

The string to pad version parts after $position

Tags
phpstan-param

string[] $matches

Return values
string|null

The new version

parseConstraint()

private parseConstraint(string $constraint) : array<string|int, mixed>
Parameters
$constraint : string
Tags
throws
UnexpectedValueException
phpstan-return

non-empty-array<ConstraintInterface>

Return values
array<string|int, mixed>

        
On this page

Search results