284 lines
4.6 KiB
PHP
284 lines
4.6 KiB
PHP
|
<?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' => '1acb94e85744589877484a13af715394b3558bd2',
|
||
|
'name' => 'getgrav/grav-plugin-admin',
|
||
|
),
|
||
|
'versions' =>
|
||
|
array (
|
||
|
'getgrav/grav-plugin-admin' =>
|
||
|
array (
|
||
|
'pretty_version' => 'dev-develop',
|
||
|
'version' => 'dev-develop',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '1acb94e85744589877484a13af715394b3558bd2',
|
||
|
),
|
||
|
'laminas/laminas-xml' =>
|
||
|
array (
|
||
|
'pretty_version' => '1.3.1',
|
||
|
'version' => '1.3.1.0',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '2eada592359aec9d9e55339270b621295cff3a4f',
|
||
|
),
|
||
|
'laminas/laminas-zendframework-bridge' =>
|
||
|
array (
|
||
|
'pretty_version' => '1.2.0',
|
||
|
'version' => '1.2.0.0',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '6cccbddfcfc742eb02158d6137ca5687d92cee32',
|
||
|
),
|
||
|
'miniflux/picofeed' =>
|
||
|
array (
|
||
|
'replaced' =>
|
||
|
array (
|
||
|
0 => '0.1.35',
|
||
|
),
|
||
|
),
|
||
|
'p3k/picofeed' =>
|
||
|
array (
|
||
|
'pretty_version' => 'v0.1.40',
|
||
|
'version' => '0.1.40.0',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => '356fd66d48779193b10ac28532cb4a4e11bb801c',
|
||
|
),
|
||
|
'scssphp/scssphp' =>
|
||
|
array (
|
||
|
'pretty_version' => 'v1.4.1',
|
||
|
'version' => '1.4.1.0',
|
||
|
'aliases' =>
|
||
|
array (
|
||
|
),
|
||
|
'reference' => 'ba86c963b94ec7ebd6e19d90cdab90d89667dbf7',
|
||
|
),
|
||
|
'symfony/polyfill-php72' =>
|
||
|
array (
|
||
|
'replaced' =>
|
||
|
array (
|
||
|
0 => '*',
|
||
|
),
|
||
|
),
|
||
|
'symfony/polyfill-php73' =>
|
||
|
array (
|
||
|
'replaced' =>
|
||
|
array (
|
||
|
0 => '*',
|
||
|
),
|
||
|
),
|
||
|
'zendframework/zendxml' =>
|
||
|
array (
|
||
|
'replaced' =>
|
||
|
array (
|
||
|
0 => '^1.2.0',
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|