MediaWiki  master
ComposerJson.php
Go to the documentation of this file.
1 <?php
2 
9 class ComposerJson {
13  private $contents;
14 
18  public function __construct( $location ) {
19  $this->contents = json_decode( file_get_contents( $location ), true );
20  }
21 
27  public function getRequiredDependencies() {
28  $deps = [];
29  if ( isset( $this->contents['require'] ) ) {
30  foreach ( $this->contents['require'] as $package => $version ) {
31  if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
32  $deps[$package] = self::normalizeVersion( $version );
33  }
34  }
35  }
36 
37  return $deps;
38  }
39 
46  public static function normalizeVersion( $version ) {
47  if ( strpos( $version, 'v' ) === 0 ) {
48  // Composer auto-strips the "v" in front of the tag name
49  $version = ltrim( $version, 'v' );
50  }
51 
52  return $version;
53  }
54 
55 }
ComposerJson\__construct
__construct( $location)
Definition: ComposerJson.php:18
ComposerJson\normalizeVersion
static normalizeVersion( $version)
Strip a leading "v" from the version name.
Definition: ComposerJson.php:46
ComposerJson
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
Definition: ComposerJson.php:9
ComposerJson\$contents
array[] $contents
Definition: ComposerJson.php:13
ComposerJson\getRequiredDependencies
getRequiredDependencies()
Dependencies as specified by composer.json.
Definition: ComposerJson.php:27