X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/libs/composer/ComposerJson.php diff --git a/includes/libs/composer/ComposerJson.php b/includes/libs/composer/ComposerJson.php new file mode 100644 index 00000000..62231a89 --- /dev/null +++ b/includes/libs/composer/ComposerJson.php @@ -0,0 +1,51 @@ +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; + } + +}