MediaWiki master
ComposerJson.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Composer;
4
15 private $contents;
16
20 public function __construct( $location ) {
21 $this->contents = json_decode( file_get_contents( $location ), true );
22 }
23
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 );
37 }
38 }
39 }
40
41 return $deps;
42 }
43
50 public static function normalizeVersion( $version ) {
51 // Composer auto-strips the "v" in front of the tag name
52 return ltrim( $version, 'v' );
53 }
54
55}
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
getRequiredDependencies()
Dependencies as specified by composer.json.
static normalizeVersion( $version)
Strip a leading "v" from the version name.