Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / libs / composer / ComposerJson.php
blobdcc57bb197d199c385229c9e939f37ea28be33d8
1 <?php
3 namespace Wikimedia\Composer;
5 /**
6 * Reads a composer.json file and provides accessors to get
7 * its hash and the required dependencies
9 * @since 1.25
11 class ComposerJson {
12 /**
13 * @var array[]
15 private $contents;
17 /**
18 * @param string $location
20 public function __construct( $location ) {
21 $this->contents = json_decode( file_get_contents( $location ), true );
24 /**
25 * Dependencies as specified by composer.json
27 * @return string[]
29 public function getRequiredDependencies() {
30 $deps = [];
31 if ( isset( $this->contents['require'] ) ) {
32 foreach ( $this->contents['require'] as $package => $version ) {
33 // Examples of package dependencies that don't have a / in the name:
34 // php, ext-xml, composer-plugin-api
35 if ( strpos( $package, '/' ) !== false ) {
36 $deps[$package] = self::normalizeVersion( $version );
41 return $deps;
44 /**
45 * Strip a leading "v" from the version name
47 * @param string $version
48 * @return string
50 public static function normalizeVersion( $version ) {
51 // Composer auto-strips the "v" in front of the tag name
52 return ltrim( $version, 'v' );