123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- namespace Composer;
- use Composer\Semver\VersionParser;
- class InstalledVersions
- {
- private static $installed = array (
- 'root' =>
- array (
- 'pretty_version' => 'dev-develop',
- 'version' => 'dev-develop',
- 'aliases' =>
- array (
- ),
- 'reference' => '47c51ab15542055b42183b14a29ed0b206e7a0f7',
- 'name' => 'trilbymedia/sitemap',
- ),
- 'versions' =>
- array (
- 'trilbymedia/sitemap' =>
- array (
- 'pretty_version' => 'dev-develop',
- 'version' => 'dev-develop',
- 'aliases' =>
- array (
- ),
- 'reference' => '47c51ab15542055b42183b14a29ed0b206e7a0f7',
- ),
- ),
- );
- public static function getInstalledPackages()
- {
- return array_keys(self::$installed['versions']);
- }
- public static function isInstalled($packageName)
- {
- return isset(self::$installed['versions'][$packageName]);
- }
- public static function satisfies(VersionParser $parser, $packageName, $constraint)
- {
- $constraint = $parser->parseConstraints($constraint);
- $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
- return $provided->matches($constraint);
- }
- public static function getVersionRanges($packageName)
- {
- if (!isset(self::$installed['versions'][$packageName])) {
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
- }
- $ranges = array();
- if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
- $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
- }
- if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
- $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
- }
- if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
- $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
- }
- if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
- $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
- }
- return implode(' || ', $ranges);
- }
- public static function getVersion($packageName)
- {
- if (!isset(self::$installed['versions'][$packageName])) {
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
- }
- if (!isset(self::$installed['versions'][$packageName]['version'])) {
- return null;
- }
- return self::$installed['versions'][$packageName]['version'];
- }
- public static function getPrettyVersion($packageName)
- {
- if (!isset(self::$installed['versions'][$packageName])) {
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
- }
- if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
- return null;
- }
- return self::$installed['versions'][$packageName]['pretty_version'];
- }
- public static function getReference($packageName)
- {
- if (!isset(self::$installed['versions'][$packageName])) {
- throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
- }
- if (!isset(self::$installed['versions'][$packageName]['reference'])) {
- return null;
- }
- return self::$installed['versions'][$packageName]['reference'];
- }
- public static function getRootPackage()
- {
- return self::$installed['root'];
- }
- public static function getRawData()
- {
- return self::$installed;
- }
- public static function reload($data)
- {
- self::$installed = $data;
- }
- }
|