Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../vendor/composer
File: InstalledVersions.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Composer.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Nils Adermann <naderman@naderman.de>
[5] Fix | Delete
* Jordi Boggiano <j.boggiano@seld.be>
[6] Fix | Delete
*
[7] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[8] Fix | Delete
* file that was distributed with this source code.
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace Composer;
[12] Fix | Delete
[13] Fix | Delete
use Composer\Autoload\ClassLoader;
[14] Fix | Delete
use Composer\Semver\VersionParser;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* This class is copied in every Composer installed project and available to all
[18] Fix | Delete
*
[19] Fix | Delete
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
[20] Fix | Delete
*
[21] Fix | Delete
* To require its presence, you can require `composer-runtime-api ^2.0`
[22] Fix | Delete
*/
[23] Fix | Delete
class InstalledVersions
[24] Fix | Delete
{
[25] Fix | Delete
private static $installed;
[26] Fix | Delete
private static $canGetVendors;
[27] Fix | Delete
private static $installedByVendor = array();
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Returns a list of all package names which are present, either by being installed, replaced or provided
[31] Fix | Delete
*
[32] Fix | Delete
* @return string[]
[33] Fix | Delete
* @psalm-return list<string>
[34] Fix | Delete
*/
[35] Fix | Delete
public static function getInstalledPackages()
[36] Fix | Delete
{
[37] Fix | Delete
$packages = array();
[38] Fix | Delete
foreach (self::getInstalled() as $installed) {
[39] Fix | Delete
$packages[] = array_keys($installed['versions']);
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if (1 === \count($packages)) {
[43] Fix | Delete
return $packages[0];
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Returns a list of all package names with a specific type e.g. 'library'
[51] Fix | Delete
*
[52] Fix | Delete
* @param string $type
[53] Fix | Delete
* @return string[]
[54] Fix | Delete
* @psalm-return list<string>
[55] Fix | Delete
*/
[56] Fix | Delete
public static function getInstalledPackagesByType($type)
[57] Fix | Delete
{
[58] Fix | Delete
$packagesByType = array();
[59] Fix | Delete
[60] Fix | Delete
foreach (self::getInstalled() as $installed) {
[61] Fix | Delete
foreach ($installed['versions'] as $name => $package) {
[62] Fix | Delete
if (isset($package['type']) && $package['type'] === $type) {
[63] Fix | Delete
$packagesByType[] = $name;
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
return $packagesByType;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Checks whether the given package is installed
[73] Fix | Delete
*
[74] Fix | Delete
* This also returns true if the package name is provided or replaced by another package
[75] Fix | Delete
*
[76] Fix | Delete
* @param string $packageName
[77] Fix | Delete
* @param bool $includeDevRequirements
[78] Fix | Delete
* @return bool
[79] Fix | Delete
*/
[80] Fix | Delete
public static function isInstalled($packageName, $includeDevRequirements = true)
[81] Fix | Delete
{
[82] Fix | Delete
foreach (self::getInstalled() as $installed) {
[83] Fix | Delete
if (isset($installed['versions'][$packageName])) {
[84] Fix | Delete
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return false;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Checks whether the given package satisfies a version constraint
[93] Fix | Delete
*
[94] Fix | Delete
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
[95] Fix | Delete
*
[96] Fix | Delete
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
[97] Fix | Delete
*
[98] Fix | Delete
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
[99] Fix | Delete
* @param string $packageName
[100] Fix | Delete
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
[101] Fix | Delete
* @return bool
[102] Fix | Delete
*/
[103] Fix | Delete
public static function satisfies(VersionParser $parser, $packageName, $constraint)
[104] Fix | Delete
{
[105] Fix | Delete
$constraint = $parser->parseConstraints($constraint);
[106] Fix | Delete
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
[107] Fix | Delete
[108] Fix | Delete
return $provided->matches($constraint);
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Returns a version constraint representing all the range(s) which are installed for a given package
[113] Fix | Delete
*
[114] Fix | Delete
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
[115] Fix | Delete
* whether a given version of a package is installed, and not just whether it exists
[116] Fix | Delete
*
[117] Fix | Delete
* @param string $packageName
[118] Fix | Delete
* @return string Version constraint usable with composer/semver
[119] Fix | Delete
*/
[120] Fix | Delete
public static function getVersionRanges($packageName)
[121] Fix | Delete
{
[122] Fix | Delete
foreach (self::getInstalled() as $installed) {
[123] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[124] Fix | Delete
continue;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
$ranges = array();
[128] Fix | Delete
if (isset($installed['versions'][$packageName]['pretty_version'])) {
[129] Fix | Delete
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
[130] Fix | Delete
}
[131] Fix | Delete
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
[132] Fix | Delete
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
[133] Fix | Delete
}
[134] Fix | Delete
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
[135] Fix | Delete
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
[136] Fix | Delete
}
[137] Fix | Delete
if (array_key_exists('provided', $installed['versions'][$packageName])) {
[138] Fix | Delete
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
return implode(' || ', $ranges);
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* @param string $packageName
[149] Fix | Delete
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
[150] Fix | Delete
*/
[151] Fix | Delete
public static function getVersion($packageName)
[152] Fix | Delete
{
[153] Fix | Delete
foreach (self::getInstalled() as $installed) {
[154] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[155] Fix | Delete
continue;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
if (!isset($installed['versions'][$packageName]['version'])) {
[159] Fix | Delete
return null;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
return $installed['versions'][$packageName]['version'];
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* @param string $packageName
[170] Fix | Delete
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
[171] Fix | Delete
*/
[172] Fix | Delete
public static function getPrettyVersion($packageName)
[173] Fix | Delete
{
[174] Fix | Delete
foreach (self::getInstalled() as $installed) {
[175] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[176] Fix | Delete
continue;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
[180] Fix | Delete
return null;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
return $installed['versions'][$packageName]['pretty_version'];
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* @param string $packageName
[191] Fix | Delete
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
[192] Fix | Delete
*/
[193] Fix | Delete
public static function getReference($packageName)
[194] Fix | Delete
{
[195] Fix | Delete
foreach (self::getInstalled() as $installed) {
[196] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[197] Fix | Delete
continue;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
if (!isset($installed['versions'][$packageName]['reference'])) {
[201] Fix | Delete
return null;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
return $installed['versions'][$packageName]['reference'];
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* @param string $packageName
[212] Fix | Delete
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
[213] Fix | Delete
*/
[214] Fix | Delete
public static function getInstallPath($packageName)
[215] Fix | Delete
{
[216] Fix | Delete
foreach (self::getInstalled() as $installed) {
[217] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[218] Fix | Delete
continue;
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* @return array
[229] Fix | Delete
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
[230] Fix | Delete
*/
[231] Fix | Delete
public static function getRootPackage()
[232] Fix | Delete
{
[233] Fix | Delete
$installed = self::getInstalled();
[234] Fix | Delete
[235] Fix | Delete
return $installed[0]['root'];
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Returns the raw installed.php data for custom implementations
[240] Fix | Delete
*
[241] Fix | Delete
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
[242] Fix | Delete
* @return array[]
[243] Fix | Delete
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
[244] Fix | Delete
*/
[245] Fix | Delete
public static function getRawData()
[246] Fix | Delete
{
[247] Fix | Delete
@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);
[248] Fix | Delete
[249] Fix | Delete
if (null === self::$installed) {
[250] Fix | Delete
// only require the installed.php file if this file is loaded from its dumped location,
[251] Fix | Delete
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
[252] Fix | Delete
if (substr(__DIR__, -8, 1) !== 'C') {
[253] Fix | Delete
self::$installed = include __DIR__ . '/installed.php';
[254] Fix | Delete
} else {
[255] Fix | Delete
self::$installed = array();
[256] Fix | Delete
}
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
return self::$installed;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
/**
[263] Fix | Delete
* Returns the raw data of all installed.php which are currently loaded for custom implementations
[264] Fix | Delete
*
[265] Fix | Delete
* @return array[]
[266] Fix | Delete
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
[267] Fix | Delete
*/
[268] Fix | Delete
public static function getAllRawData()
[269] Fix | Delete
{
[270] Fix | Delete
return self::getInstalled();
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Lets you reload the static array from another file
[275] Fix | Delete
*
[276] Fix | Delete
* This is only useful for complex integrations in which a project needs to use
[277] Fix | Delete
* this class but then also needs to execute another project's autoloader in process,
[278] Fix | Delete
* and wants to ensure both projects have access to their version of installed.php.
[279] Fix | Delete
*
[280] Fix | Delete
* A typical case would be PHPUnit, where it would need to make sure it reads all
[281] Fix | Delete
* the data it needs from this class, then call reload() with
[282] Fix | Delete
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
[283] Fix | Delete
* the project in which it runs can then also use this class safely, without
[284] Fix | Delete
* interference between PHPUnit's dependencies and the project's dependencies.
[285] Fix | Delete
*
[286] Fix | Delete
* @param array[] $data A vendor/composer/installed.php data set
[287] Fix | Delete
* @return void
[288] Fix | Delete
*
[289] Fix | Delete
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
[290] Fix | Delete
*/
[291] Fix | Delete
public static function reload($data)
[292] Fix | Delete
{
[293] Fix | Delete
self::$installed = $data;
[294] Fix | Delete
self::$installedByVendor = array();
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* @return array[]
[299] Fix | Delete
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
[300] Fix | Delete
*/
[301] Fix | Delete
private static function getInstalled()
[302] Fix | Delete
{
[303] Fix | Delete
if (null === self::$canGetVendors) {
[304] Fix | Delete
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
$installed = array();
[308] Fix | Delete
[309] Fix | Delete
if (self::$canGetVendors) {
[310] Fix | Delete
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
[311] Fix | Delete
if (isset(self::$installedByVendor[$vendorDir])) {
[312] Fix | Delete
$installed[] = self::$installedByVendor[$vendorDir];
[313] Fix | Delete
} elseif (is_file($vendorDir.'/composer/installed.php')) {
[314] Fix | Delete
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
[315] Fix | Delete
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
[316] Fix | Delete
self::$installed = $installed[count($installed) - 1];
[317] Fix | Delete
}
[318] Fix | Delete
}
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
if (null === self::$installed) {
[323] Fix | Delete
// only require the installed.php file if this file is loaded from its dumped location,
[324] Fix | Delete
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
[325] Fix | Delete
if (substr(__DIR__, -8, 1) !== 'C') {
[326] Fix | Delete
self::$installed = require __DIR__ . '/installed.php';
[327] Fix | Delete
} else {
[328] Fix | Delete
self::$installed = array();
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
$installed[] = self::$installed;
[332] Fix | Delete
[333] Fix | Delete
return $installed;
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function