3 namespace Wikimedia\Composer
;
6 * Reads a composer.json file and provides accessors to get
7 * its hash and the required dependencies
18 * @param string $location
20 public function __construct( $location ) {
21 $this->contents
= json_decode( file_get_contents( $location ), true );
25 * Dependencies as specified by composer.json
29 public function getRequiredDependencies() {
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 );
45 * Strip a leading "v" from the version name
47 * @param string $version
50 public static function normalizeVersion( $version ) {
51 // Composer auto-strips the "v" in front of the tag name
52 return ltrim( $version, 'v' );