Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / libs / composer / ComposerJson.php
blob62231a89b61079370b83d055960cbd6d2fec6014
1 <?php
3 /**
4 * Reads a composer.json file and provides accessors to get
5 * its hash and the required dependencies
7 * @since 1.25
8 */
9 class ComposerJson {
11 /**
12 * @param string $location
14 public function __construct( $location ) {
15 $this->contents = json_decode( file_get_contents( $location ), true );
18 /**
19 * Dependencies as specified by composer.json
21 * @return array
23 public function getRequiredDependencies() {
24 $deps = [];
25 if ( isset( $this->contents['require'] ) ) {
26 foreach ( $this->contents['require'] as $package => $version ) {
27 if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
28 $deps[$package] = self::normalizeVersion( $version );
33 return $deps;
36 /**
37 * Strip a leading "v" from the version name
39 * @param string $version
40 * @return string
42 public static function normalizeVersion( $version ) {
43 if ( strpos( $version, 'v' ) === 0 ) {
44 // Composer auto-strips the "v" in front of the tag name
45 $version = ltrim( $version, 'v' );
48 return $version;