MediaWiki  master
ComposerVersionNormalizer.php
Go to the documentation of this file.
1 <?php
2 
8 
23  public function normalizeSuffix( $version ) {
24  if ( !is_string( $version ) ) {
25  throw new InvalidArgumentException( '$version must be a string' );
26  }
27 
28  return preg_replace( '/^(\d[\d\.]*)([a-zA-Z]+)(\d*)$/', '$1-$2$3', $version, 1 );
29  }
30 
46  public function normalizeLevelCount( $version ) {
47  if ( !is_string( $version ) ) {
48  throw new InvalidArgumentException( '$version must be a string' );
49  }
50 
51  $dashPosition = strpos( $version, '-' );
52 
53  if ( $dashPosition !== false ) {
54  $suffix = substr( $version, $dashPosition );
55  $version = substr( $version, 0, $dashPosition );
56  }
57 
58  $version = implode( '.', array_pad( explode( '.', $version, 4 ), 4, '0' ) );
59 
60  if ( $dashPosition !== false ) {
61  $version .= $suffix;
62  }
63 
64  return $version;
65  }
66 }
normalizeSuffix( $version)
Ensures there is a dash in between the version and the stability suffix.
normalizeLevelCount( $version)
Ensures the version has four levels.