Merge "Use content language for edit summary on upload overwrite"
[lhc/web/wiklou.git] / includes / libs / composer / ComposerJson.php
1 <?php
2
3 /**
4 * Reads a composer.json file and provides accessors to get
5 * its hash and the required dependencies
6 *
7 * @since 1.25
8 */
9 class ComposerJson {
10
11 /**
12 * @param string $location
13 */
14 public function __construct( $location ) {
15 $this->hash = md5_file( $location );
16 $this->contents = json_decode( file_get_contents( $location ), true );
17 }
18
19 public function getHash() {
20 return $this->hash;
21 }
22
23 /**
24 * Dependencies as specified by composer.json
25 *
26 * @return array
27 */
28 public function getRequiredDependencies() {
29 $deps = array();
30 foreach ( $this->contents['require'] as $package => $version ) {
31 if ( $package !== "php" ) {
32 $deps[$package] = self::normalizeVersion( $version );
33 }
34 }
35
36 return $deps;
37 }
38
39 /**
40 * Strip a leading "v" from the version name
41 *
42 * @param string $version
43 * @return string
44 */
45 public static function normalizeVersion( $version ) {
46 if ( strpos( $version, 'v' ) === 0 ) {
47 // Composer auto-strips the "v" in front of the tag name
48 $version = ltrim( $version, 'v' );
49 }
50
51 return $version;
52 }
53
54 }