private function format_version($version)
{
if (preg_match('~^\\d+\\.\\d+\\.\\d+~', $version)) {
return $version;
}
// Semantic Versioning at least requires the format "X.Y.Z" with X, Y and Z being non-negative integers.
$parts = [0, 0, 0];
$replace = true;
foreach (explode('.', $version) as $index => $level) {
if ($index < 3 && $replace) {
if (is_numeric($level)) {
$parts[$index] = (int) $level;
continue;
}
// Since this is a non-numeric part, all other parts will be appended (and not update existing levels).
$replace = false;
}
$parts[] = $level;
}
return join('.', $parts);
}