mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-10 10:38:43 +00:00
238 lines
3.7 KiB
PHP
238 lines
3.7 KiB
PHP
|
<?php
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
namespace Composer;
|
||
|
|
||
|
use Composer\Semver\VersionParser;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
class InstalledVersions
|
||
|
{
|
||
|
private static $installed = array (
|
||
|
'root' =>
|
||
|
array (
|
||
|
'pretty_version' => 'dev-master',
|
||
|
'version' => 'dev-master',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '0d931e270b425b35fabb421ea21043ba2aaf9786',
|
||
|
'name' => '__root__',
|
||
|
),
|
||
|
'versions' =>
|
||
|
array (
|
||
|
'__root__' =>
|
||
|
array (
|
||
|
'pretty_version' => 'dev-master',
|
||
|
'version' => 'dev-master',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '0d931e270b425b35fabb421ea21043ba2aaf9786',
|
||
|
),
|
||
|
'gregwar/captcha' =>
|
||
|
array (
|
||
|
'pretty_version' => 'v1.1.9',
|
||
|
'version' => '1.1.9.0',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '4bb668e6b40e3205a020ca5ee4ca8cff8b8780c5',
|
||
|
),
|
||
|
'symfony/finder' =>
|
||
|
array (
|
||
|
'pretty_version' => 'v6.0.3',
|
||
|
'version' => '6.0.3.0',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '8661b74dbabc23223f38c9b99d3f8ade71170430',
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|