4 * Reads a composer.json file and provides accessors to get
5 * its hash and the required dependencies
12 * @param string $location
14 public function __construct( $location ) {
15 $this->hash
= md5_file( $location );
16 $this->contents
= json_decode( file_get_contents( $location ), true );
19 public function getHash() {
24 * Dependencies as specified by composer.json
28 public function getRequiredDependencies() {
30 foreach ( $this->contents
['require'] as $package => $version ) {
31 if ( $package !== "php" ) {
32 $deps[$package] = self
::normalizeVersion( $version );
40 * Strip a leading "v" from the version name
42 * @param string $version
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' );