MediaWiki REL1_34
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 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}
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)