wiki.techinc.nl/includes/libs/composer/ComposerJson.php
Kunal Mehta 75fefc066b checkComposerLockUpToDate: Always check dependencies
Upstream composer has replaced the 'hash' with a smarter 'content-hash',
but instead of re-implementing (or copy-pasting) all of that in MediaWiki
we can just compare the dependencies themselves, since that's all we
care about.

Bug: T147189
Change-Id: Ic2f22a82699e2b707b6ccb355605999a183a56a0
2016-10-16 12:49:41 -07:00

51 lines
1 KiB
PHP

<?php
/**
* Reads a composer.json file and provides accessors to get
* its hash and the required dependencies
*
* @since 1.25
*/
class ComposerJson {
/**
* @param string $location
*/
public function __construct( $location ) {
$this->contents = json_decode( file_get_contents( $location ), true );
}
/**
* Dependencies as specified by composer.json
*
* @return array
*/
public function getRequiredDependencies() {
$deps = [];
if ( isset( $this->contents['require'] ) ) {
foreach ( $this->contents['require'] as $package => $version ) {
if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
$deps[$package] = self::normalizeVersion( $version );
}
}
}
return $deps;
}
/**
* Strip a leading "v" from the version name
*
* @param string $version
* @return string
*/
public static function normalizeVersion( $version ) {
if ( strpos( $version, 'v' ) === 0 ) {
// Composer auto-strips the "v" in front of the tag name
$version = ltrim( $version, 'v' );
}
return $version;
}
}