version_support
final class version_support
| internal |
Infrastructure service to normalize and compare Moodle Core versions.
This class normalizes core data to a "semver-like" format (x.y.z) and exposes convenient comparators (>=, ranges, feature gate via declarative matrix). Values are cached in memory after the first read from {\local_middag\framework\support\moodle\bootstrap()}.
Methods
Retrieves the "semver-like" version of Moodle (e.g.: "4.4.0").
Retrieves the numeric Moodle branch (e.g.: 404 for 4.4).
Retrieves the numeric Moodle build (e.g.: 2024042200).
Compares the current Moodle version with a simple constraint.
Checks if the current version is at least the specified one.
Checks if the current version is between [min, max], inclusive.
Ensures the minimum version is met; otherwise throws an exception.
Checks if a feature is supported according to a declarative matrix.
Returns a [major, minor] pair, e.g.: [4, 4].
Details
at line 58
static string
version_semver()
Retrieves the "semver-like" version of Moodle (e.g.: "4.4.0").
The representation is preferably derived from {$CFG->branch} (more predictable) and, as a fallback, from parsing {$CFG->release}.
at line 73
static int
branch()
Retrieves the numeric Moodle branch (e.g.: 404 for 4.4).
at line 87
static int
build()
Retrieves the numeric Moodle build (e.g.: 2024042200).
Useful for patch/build comparisons when necessary.
at line 110
static bool
compare(string $operator, string $constraint)
Compares the current Moodle version with a simple constraint.
The constraint accepts "x.y" or "x.y.z". The operator is passed to {\local_middag\framework\support\moodle\version_compare()}.
at line 131
static bool
at_least(string $min)
Checks if the current version is at least the specified one.
Syntactic sugar for {\local_middag\framework\support\moodle\compare()} with ">=" operator.
at line 148
static bool
between(string $min, string $max)
Checks if the current version is between [min, max], inclusive.
at line 167
static void
assert_min(string $min, string|null $msg = null)
Ensures the minimum version is met; otherwise throws an exception.
If no message is provided, an internationalized message is used ({local_middag/lang/* requiresmoodlemin}).
at line 198
static bool
supports(string $feature, array $matrix)
Checks if a feature is supported according to a declarative matrix.
Each map entry accepts the keys:
- "since" => minimum version (inclusive)
- "until" => maximum version (inclusive)
at line 221
static array
major_minor()
Returns a [major, minor] pair, e.g.: [4, 4].
Useful for quick switches by major/minor version.