wishthis/vendor/composer/InstalledVersions.php
2022-10-09 13:01:52 +02:00

484 lines
9.2 KiB
PHP

<?php
namespace Composer;
use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;
class InstalledVersions
{
private static $installed = array (
'root' =>
array (
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'aliases' =>
array (
),
'reference' => '0ffe21fd25ad5261d9a9aad7202ba083a5afceb1',
'name' => '__root__',
),
'versions' =>
array (
'__root__' =>
array (
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'aliases' =>
array (
),
'reference' => '0ffe21fd25ad5261d9a9aad7202ba083a5afceb1',
),
'composer/ca-bundle' =>
array (
'pretty_version' => '1.3.3',
'version' => '1.3.3.0',
'aliases' =>
array (
),
'reference' => '30897edbfb15e784fe55587b4f73ceefd3c4d98c',
),
'embed/embed' =>
array (
'pretty_version' => 'v4.4.6',
'version' => '4.4.6.0',
'aliases' =>
array (
),
'reference' => '9cb2dff5c82201bbf653b7396d533d1914ff4517',
),
'gettext/gettext' =>
array (
'pretty_version' => 'v5.7.0',
'version' => '5.7.0.0',
'aliases' =>
array (
),
'reference' => '8657e580747bb3baacccdcebe69cac094661e404',
),
'gettext/languages' =>
array (
'pretty_version' => '2.9.0',
'version' => '2.9.0.0',
'aliases' =>
array (
),
'reference' => 'ed56dd2c7f4024cc953ed180d25f02f2640e3ffa',
),
'gettext/translator' =>
array (
'pretty_version' => 'v1.1.1',
'version' => '1.1.1.0',
'aliases' =>
array (
),
'reference' => 'b18ff33e8203de623854561f5e47e992fc5c50bb',
),
'grandel/include-directory' =>
array (
'pretty_version' => 'v0.2.2',
'version' => '0.2.2.0',
'aliases' =>
array (
),
'reference' => 'a5c830e8f1527c818b521ab18f2accecb02f9919',
),
'guzzlehttp/guzzle' =>
array (
'pretty_version' => '7.5.0',
'version' => '7.5.0.0',
'aliases' =>
array (
),
'reference' => 'b50a2a1251152e43f6a37f0fa053e730a67d25ba',
),
'guzzlehttp/promises' =>
array (
'pretty_version' => '1.5.2',
'version' => '1.5.2.0',
'aliases' =>
array (
),
'reference' => 'b94b2807d85443f9719887892882d0329d1e2598',
),
'guzzlehttp/psr7' =>
array (
'pretty_version' => '2.4.1',
'version' => '2.4.1.0',
'aliases' =>
array (
),
'reference' => '69568e4293f4fa993f3b0e51c9723e1e17c41379',
),
'ml/iri' =>
array (
'pretty_version' => '1.1.4',
'version' => '1.1.4.0',
'aliases' =>
array (
),
'reference' => 'cbd44fa913e00ea624241b38cefaa99da8d71341',
),
'ml/json-ld' =>
array (
'pretty_version' => '1.2.1',
'version' => '1.2.1.0',
'aliases' =>
array (
),
'reference' => '537e68e87a6bce23e57c575cd5dcac1f67ce25d8',
),
'oscarotero/html-parser' =>
array (
'pretty_version' => 'v0.1.6',
'version' => '0.1.6.0',
'aliases' =>
array (
),
'reference' => 'b61e92f634d0dc184339d24630a6968d3ac64ded',
),
'psr/http-client' =>
array (
'pretty_version' => '1.0.1',
'version' => '1.0.1.0',
'aliases' =>
array (
),
'reference' => '2dfb5f6c5eff0e91e20e913f8c5452ed95b86621',
),
'psr/http-client-implementation' =>
array (
'provided' =>
array (
0 => '1.0',
),
),
'psr/http-factory' =>
array (
'pretty_version' => '1.0.1',
'version' => '1.0.1.0',
'aliases' =>
array (
),
'reference' => '12ac7fcd07e5b077433f5f2bee95b3a771bf61be',
),
'psr/http-factory-implementation' =>
array (
'provided' =>
array (
0 => '1.0',
),
),
'psr/http-message' =>
array (
'pretty_version' => '1.0.1',
'version' => '1.0.1.0',
'aliases' =>
array (
),
'reference' => 'f6561bf28d520154e4b0ec72be95418abe6d9363',
),
'psr/http-message-implementation' =>
array (
'provided' =>
array (
0 => '1.0',
),
),
'qferr/mjml-php' =>
array (
'pretty_version' => '1.1.0',
'version' => '1.1.0.0',
'aliases' =>
array (
),
'reference' => 'c6ea36c190e304e399a957f7e03b5a378faf41b9',
),
'ralouphie/getallheaders' =>
array (
'pretty_version' => '3.0.3',
'version' => '3.0.3.0',
'aliases' =>
array (
),
'reference' => '120b605dfeb996808c31b6477290a714d356e822',
),
'symfony/deprecation-contracts' =>
array (
'pretty_version' => 'v3.1.1',
'version' => '3.1.1.0',
'aliases' =>
array (
),
'reference' => '07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918',
),
'symfony/polyfill-php80' =>
array (
'pretty_version' => 'v1.26.0',
'version' => '1.26.0.0',
'aliases' =>
array (
),
'reference' => 'cfa0ae98841b9e461207c13ab093d76b0fa7bace',
),
'symfony/process' =>
array (
'pretty_version' => 'v5.4.11',
'version' => '5.4.11.0',
'aliases' =>
array (
),
'reference' => '6e75fe6874cbc7e4773d049616ab450eff537bf1',
),
),
);
private static $canGetVendors;
private static $installedByVendor = array();
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
public static function isInstalled($packageName)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return true;
}
}
return false;
}
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)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
public static function getRawData()
{
return self::$installed;
}
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
}
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
if (self::$canGetVendors) {
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
}
}
}
$installed[] = self::$installed;
return $installed;
}
}