Index

MMO\core\versions

MMO\core\versions · 15 symbols · generated 30 Sep 2026

function

check

versions.php:358

Test a version string against a Composer-style constraint string.

function check(string $version, string $constraint): bool
Namespace
MMO\core\versions
See
https://getcomposer.org/doc/articles/versions.md # Exact Version Constraint Example: 1.0.2
# Version Range By using comparison operators you can specify ranges of valid versions. Valid operators are >, >=, <, <=, !=. You can define multiple ranges. Ranges separated by a space ( ) or comma (,) will be treated as a logical AND. A double pipe (||) will be treated as a logical OR. AND has higher precedence than OR. Examples: >=1.0 >=1.0 <2.0 >=1.0 <1.1 || >=1.2 # Hyphenated Version Range (-) Inclusive set of versions. Partial versions on the right include are completed with a wildcard. For example 1.0 - 2.0 is equivalent to >=1.0.0 <2.1 as the 2.0 becomes 2.0.*. Example: 1.0 - 2.0 # Wildcard Version Range (.*) You can specify a pattern with a * wildcard. 1.0.* is the equivalent of >=1.0 <1.1. Example: 1.0.*
$versionstring
$constraintstring
returnsbool
check('1.0', '>=1.0 <1.1 || >=1.2 !=1.22 1.2.*'): true check('1.1', '>=1.0 <1.1 || >=1.2 !=1.22 1.2.*'): false check('1.2', '>=1.0 <1.1 || >=1.2 !=1.22 1.2.*'): true check('1.22', '>=1.0 <1.1 || >=1.2 !=1.22 1.2.*'): false
Call graph
function

clean

versions.php:208

Normalize a version string to its canonical split()+join() round-tripped form.

function clean(string $version): string
Namespace
MMO\core\versions
$versionstring
returnsstring
clean('1.2.3-ALPha'); // '1.2.3.alpha'
Call graph

Uses (2)

function

compare

versions.php:246

Compare two versions per Semantic Versioning precedence rules (numeric identifiers compared numerically, alphabetic ones lexically, a shorter prerelease set precedes a longer one that's otherwise identical, ...).

function compare(array|string $v1, array|string $v2, string $op = ''): int|bool
Namespace
MMO\core\versions
A `'*'` in either version matches anything at that position (so `1.*` compares equal to `1.2.3`).
$v1array | string
$v2array | string
$op = ''stringthe operator to use: '<', '<=', '>', '>=', '=', '!=', or '' for no operator
returnsint | boola bool if $op is given (whether the comparison holds); otherwise an int: >0 if $v1 > $v2, =0 if $v1 == $v2 (or either is a matching wildcard), <0 if $v1 < $v2
compare('1.1', '1.2'); // -1 compare('1.0', '1.0.0'); // 0 compare('1.*', '1.3.4'); // 0 -- wildcard matches compare('1.2.3', '1.2', '>'); // true
Call graph

Uses (1)

Used by (2)

function

findVersion

versions.php:453

Find the version(s) in $versions that satisfy $constraint.

function findVersion(array $versions, string $constraint, bool $single = true): array|string|null
Namespace
MMO\core\versions
$versionsarraya list of version strings
$constraintstringa Composer-style constraint, check()
$single = trueboolif true, return only the single highest matching version (or null if none match); if false, return every matching version, highest first
returnsarray | string | null
findVersion(['1.0', '1.1', '2.0'], '>=1.0 <2.0'); // '1.1' (the highest match) findVersion(['1.0', '1.1', '2.0'], '>=1.0 <2.0', false); // ['1.1', '1.0'] findVersion(['1.0'], '>=2.0'); // null
Call graph
function

hasAny

versions.php:128

Test if a version (string, or already-split() array) has a wildcard in any of its first 3 (major/ minor/patch) positions -- unlike isAny(), a partial wildcard like '1.*' counts.

function hasAny(array|string $version): bool
Namespace
MMO\core\versions
$versionarray | string
returnsbool
hasAny('1.*'); // true hasAny('1.2.3'); // false
Call graph

Uses (1)

function

inc

versions.php:224

Increment one component (major/minor/patch) of a version, returning the new version string.

function inc(string $version, int $where = MMO\core\versions\PATCH, int $inc = 1): string
Namespace
MMO\core\versions
$versionstring
$where = MMO\core\versions\PATCHintone of the MAJOR/MINOR/PATCH constants: which component to increment
$inc = 1intthe amount to increment by (can be negative to decrement)
returnsstring
throwsif $where is not MAJOR/MINOR/PATCH
inc('1.2.3'); // '1.2.4' (defaults to PATCH) inc('1.2.3', MINOR); // '1.3.3' inc('1.2.3', MAJOR, 2); // '3.2.3'
Call graph
function

isAny

versions.php:115

Test if a version (string, or already-split() array) is a bare wildcard: '*', or a split version whose first 3 elements are all '*' (i.e. it matches literally anything).

function isAny(array|string $version): bool
Namespace
MMO\core\versions
$versionarray | string
returnsbool
isAny('*'); // true isAny(split('*')); // true ([‘*’,’*’,’*’]) isAny('1.*'); // false -- only a partial wildcard, use hasAny() for that
Call graph
function

join

versions.php:192

Reverse of split(): join a split version back into a string, replacing a negative stability int back into its word form (the first STABILITY key with that value -- STABILITY).

function join(array $version, string $metadata = ''): string
Namespace
MMO\core\versions
$versionarray
$metadata = ''stringoptional build metadata to append as +$metadata
returnsstring
join([1, 2, 3]); // '1.2.3' join([1, 2, 3, -6]); // '1.2.3.alpha' join([1, 0, 0], 'abc'); // '1.0.0+abc'
Call graph

Used by (3)

function

ksort

versions.php:472

Sort an array by its KEYS, treating them as version numbers (sortCompare()).

function ksort(array $versions, bool $asc = true): array
Namespace
MMO\core\versions
$versionsarray
$asc = trueboolif false, sort highest-first instead of lowest-first
returnsarray
ksort(['1.1' => 'a', '1.0' => 'b', '2.0' => 'c']); // ['1.0' => 'b', '1.1' => 'a', '2.0' => 'c']
Call graph
function

loopVersions

versions.php:432

Lazily yield every version in $versions that satisfies $constraint, from highest to lowest (sort()).

function loopVersions(array $versions, string $constraint): Generator
Namespace
MMO\core\versions
$versionsarraya list of version strings
$constraintstringa Composer-style constraint, check()
returnsGenerator
foreach (loopVersions(['1.0', '1.1', '2.0'], '>=1.0 <2.0') as $v) {...} // yields '1.1', then '1.0'
Call graph
function

metadata

versions.php:139

Extract a version's build metadata (the part after '+'), without normalizing the rest of the string.

function metadata(string $version): string
Namespace
MMO\core\versions
$versionstring
returnsstring'' if there is no metadata
metadata('1.0.0+20130313144700'); // '20130313144700'
function

normalize

versions.php:95

Normalize a version string: strip its build metadata (the +... suffix, captured into &$metadata), and turn separators (_, -, +, spaces) plus letter/digit boundaries into ., so it can be cleanly exploded on . afterwards (split()).

function normalize(string $version, ?string &$metadata = null): string
Namespace
MMO\core\versions
$versionstring
$metadata = nullnull | string
returnsstring
normalize('1.2.3-alpha+001', $meta); // '1.2.3.alpha', $meta = '001' normalize('1.2_test'); // '1.2.test'
Call graph
function

sort

versions.php:484

Sort an array by its VALUES, treating them as version numbers (sortCompare()).

function sort(array $versions, bool $asc = true): array
Namespace
MMO\core\versions
$versionsarraya list of version strings
$asc = trueboolif false, sort highest-first instead of lowest-first
returnsarray
sort(['1.1', '1.0', '2.0']); // ['1.0', '1.1', '2.0']
Call graph
function

sortCompare

versions.php:302

Same as compare() (with no operator), except a wildcard version always sorts BEFORE the versions it matches (so 1.* sorts before 1.2.3) rather than comparing equal to them -- this is what makes sort() a stable, total ordering instead of treating every wildcard-matching version as interchangeable.

function sortCompare(string $a, string $b): int
Namespace
MMO\core\versions
$astring
$bstring
returnsintnegative if $a sorts before $b, positive if after, 0 if equal
sortCompare('1.*', '1.2'); // -1 -- the wildcard sorts first
Call graph
function

split

versions.php:155

Split a version string into an array of at least 3 elements [major, minor, patch, ...prerelease], per Semantic Versioning. Numeric parts become int, a recognized stability word (STABILITY) becomes its (negative) int, anything else stays a string, and * stays the literal string '*' (a wildcard).

function split(string $version): array
Namespace
MMO\core\versions
$versionstring
returnsarray
split('1.2.3'); // [1, 2, 3] split('1.2.3-alpha'); // [1, 2, 3, -6] -- STABILITY['alpha'] split('1.*'); // [1, '*', '*'] split('1.2.3-test'); // [1, 2, 3, 'test'] -- unrecognized word, kept as a string
Call graph