PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / libs / composer / ComposerJson.php
blobbb55ac638074a190d00dbefce6a50cb981a3a497
1 <?php
3 /**
4 * Reads a composer.json file and provides accessors to get
5 * its hash and the required dependencies
7 * @since 1.25
8 */
9 class ComposerJson {
11 /**
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() {
20 return $this->hash;
23 /**
24 * Dependencies as specified by composer.json
26 * @return array
28 public function getRequiredDependencies() {
29 $deps = array();
30 if ( isset( $this->contents['require'] ) ) {
31 foreach ( $this->contents['require'] as $package => $version ) {
32 if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
33 $deps[$package] = self::normalizeVersion( $version );
38 return $deps;
41 /**
42 * Strip a leading "v" from the version name
44 * @param string $version
45 * @return string
47 public static function normalizeVersion( $version ) {
48 if ( strpos( $version, 'v' ) === 0 ) {
49 // Composer auto-strips the "v" in front of the tag name
50 $version = ltrim( $version, 'v' );
53 return $version;