412 lines
7.3 KiB
PHP
412 lines
7.3 KiB
PHP
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Composer;
|
|
|
|
use Composer\Autoload\ClassLoader;
|
|
use Composer\Semver\VersionParser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InstalledVersions
|
|
{
|
|
private static $installed = array (
|
|
'root' =>
|
|
array (
|
|
'pretty_version' => '1.0.0+no-version-set',
|
|
'version' => '1.0.0.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => NULL,
|
|
'name' => '__root__',
|
|
),
|
|
'versions' =>
|
|
array (
|
|
'__root__' =>
|
|
array (
|
|
'pretty_version' => '1.0.0+no-version-set',
|
|
'version' => '1.0.0.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => NULL,
|
|
),
|
|
'guzzlehttp/guzzle' =>
|
|
array (
|
|
'pretty_version' => '7.3.0',
|
|
'version' => '7.3.0.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => '7008573787b430c1c1f650e3722d9bba59967628',
|
|
),
|
|
'guzzlehttp/promises' =>
|
|
array (
|
|
'pretty_version' => '1.4.1',
|
|
'version' => '1.4.1.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => '8e7d04f1f6450fef59366c399cfad4b9383aa30d',
|
|
),
|
|
'guzzlehttp/psr7' =>
|
|
array (
|
|
'pretty_version' => '1.8.2',
|
|
'version' => '1.8.2.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => 'dc960a912984efb74d0a90222870c72c87f10c91',
|
|
),
|
|
'mstilkerich/carddavclient' =>
|
|
array (
|
|
'pretty_version' => 'v1.1.0',
|
|
'version' => '1.1.0.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => '01731a7d8cc34e58a7b25ae5cfd099a2230895fa',
|
|
),
|
|
'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-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',
|
|
),
|
|
),
|
|
'psr/log' =>
|
|
array (
|
|
'pretty_version' => '1.1.4',
|
|
'version' => '1.1.4.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => 'd49695b909c3b7628b6289db5479a1c204601f11',
|
|
),
|
|
'ralouphie/getallheaders' =>
|
|
array (
|
|
'pretty_version' => '3.0.3',
|
|
'version' => '3.0.3.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => '120b605dfeb996808c31b6477290a714d356e822',
|
|
),
|
|
'sabre/uri' =>
|
|
array (
|
|
'pretty_version' => '2.2.1',
|
|
'version' => '2.2.1.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => 'f502edffafea8d746825bd5f0b923a60fd2715ff',
|
|
),
|
|
'sabre/vobject' =>
|
|
array (
|
|
'pretty_version' => '4.3.5',
|
|
'version' => '4.3.5.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => 'd8a0a9ae215a8acfb51afc29101c7344670b9c83',
|
|
),
|
|
'sabre/xml' =>
|
|
array (
|
|
'pretty_version' => '2.2.3',
|
|
'version' => '2.2.3.0',
|
|
'aliases' =>
|
|
array (
|
|
),
|
|
'reference' => 'c3b959f821c19b36952ec4a595edd695c216bfc6',
|
|
),
|
|
),
|
|
);
|
|
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()
|
|
{
|
|
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
|
|
|
return self::$installed;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function getAllRawData()
|
|
{
|
|
return self::getInstalled();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|