Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / composer / ComposerVersionNormalizer.php
bloba0d31cf2a96bb57e2a151deaa02d155c24200276
1 <?php
3 /**
4 * @licence GNU GPL v2+
5 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
6 */
7 class ComposerVersionNormalizer {
9 /**
10 * Ensures there is a dash in between the version and the stability suffix.
12 * Examples:
13 * - 1.23RC => 1.23-RC
14 * - 1.23alpha => 1.23-alpha
15 * - 1.23alpha3 => 1.23-alpha3
16 * - 1.23-beta => 1.23-beta
18 * @param string $version
20 * @return string
21 * @throws InvalidArgumentException
23 public function normalizeSuffix( $version ) {
24 if ( !is_string( $version ) ) {
25 throw new InvalidArgumentException( '$version must be a string' );
28 return preg_replace( '/^(\d[\d\.]*)([a-zA-Z]+)(\d*)$/', '$1-$2$3', $version, 1 );
31 /**
32 * Ensures the version has four levels.
33 * Version suffixes are supported, as long as they start with a dash.
35 * Examples:
36 * - 1.19 => 1.19.0.0
37 * - 1.19.2.3 => 1.19.2.3
38 * - 1.19-alpha => 1.19.0.0-alpha
39 * - 1337 => 1337.0.0.0
41 * @param string $version
43 * @return string
44 * @throws InvalidArgumentException
46 public function normalizeLevelCount( $version ) {
47 if ( !is_string( $version ) ) {
48 throw new InvalidArgumentException( '$version must be a string' );
51 $dashPosition = strpos( $version, '-' );
53 if ( $dashPosition !== false ) {
54 $suffix = substr( $version, $dashPosition );
55 $version = substr( $version, 0, $dashPosition );
58 $version = implode( '.', array_pad( explode( '.', $version ), 4, '0' ) );
60 if ( $dashPosition !== false ) {
61 $version .= $suffix;
64 return $version;