MediaWiki REL1_37
ComposerJson.php
Go to the documentation of this file.
1<?php
2
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 // Examples of package dependancies that don't have a / in the name:
32 // php, ext-xml, composer-plugin-api
33 if ( strpos( $package, '/' ) !== false ) {
34 $deps[$package] = self::normalizeVersion( $version );
35 }
36 }
37 }
38
39 return $deps;
40 }
41
48 public static function normalizeVersion( $version ) {
49 if ( strpos( $version, 'v' ) === 0 ) {
50 // Composer auto-strips the "v" in front of the tag name
51 $version = ltrim( $version, 'v' );
52 }
53
54 return $version;
55 }
56
57}
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
static normalizeVersion( $version)
Strip a leading "v" from the version name.
getRequiredDependencies()
Dependencies as specified by composer.json.
array[] $contents
__construct( $location)