Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../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
* @final
[24] Fix | Delete
*/
[25] Fix | Delete
class InstalledVersions
[26] Fix | Delete
{
[27] Fix | Delete
/**
[28] Fix | Delete
* @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
[29] Fix | Delete
* @internal
[30] Fix | Delete
*/
[31] Fix | Delete
private static $selfDir = null;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* @var mixed[]|null
[35] Fix | Delete
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
[36] Fix | Delete
*/
[37] Fix | Delete
private static $installed;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* @var bool
[41] Fix | Delete
*/
[42] Fix | Delete
private static $installedIsLocalDir;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* @var bool|null
[46] Fix | Delete
*/
[47] Fix | Delete
private static $canGetVendors;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* @var array[]
[51] Fix | Delete
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
[52] Fix | Delete
*/
[53] Fix | Delete
private static $installedByVendor = array();
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Returns a list of all package names which are present, either by being installed, replaced or provided
[57] Fix | Delete
*
[58] Fix | Delete
* @return string[]
[59] Fix | Delete
* @psalm-return list<string>
[60] Fix | Delete
*/
[61] Fix | Delete
public static function getInstalledPackages()
[62] Fix | Delete
{
[63] Fix | Delete
$packages = array();
[64] Fix | Delete
foreach (self::getInstalled() as $installed) {
[65] Fix | Delete
$packages[] = array_keys($installed['versions']);
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
if (1 === \count($packages)) {
[69] Fix | Delete
return $packages[0];
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Returns a list of all package names with a specific type e.g. 'library'
[77] Fix | Delete
*
[78] Fix | Delete
* @param string $type
[79] Fix | Delete
* @return string[]
[80] Fix | Delete
* @psalm-return list<string>
[81] Fix | Delete
*/
[82] Fix | Delete
public static function getInstalledPackagesByType($type)
[83] Fix | Delete
{
[84] Fix | Delete
$packagesByType = array();
[85] Fix | Delete
[86] Fix | Delete
foreach (self::getInstalled() as $installed) {
[87] Fix | Delete
foreach ($installed['versions'] as $name => $package) {
[88] Fix | Delete
if (isset($package['type']) && $package['type'] === $type) {
[89] Fix | Delete
$packagesByType[] = $name;
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
return $packagesByType;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Checks whether the given package is installed
[99] Fix | Delete
*
[100] Fix | Delete
* This also returns true if the package name is provided or replaced by another package
[101] Fix | Delete
*
[102] Fix | Delete
* @param string $packageName
[103] Fix | Delete
* @param bool $includeDevRequirements
[104] Fix | Delete
* @return bool
[105] Fix | Delete
*/
[106] Fix | Delete
public static function isInstalled($packageName, $includeDevRequirements = true)
[107] Fix | Delete
{
[108] Fix | Delete
foreach (self::getInstalled() as $installed) {
[109] Fix | Delete
if (isset($installed['versions'][$packageName])) {
[110] Fix | Delete
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return false;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Checks whether the given package satisfies a version constraint
[119] Fix | Delete
*
[120] Fix | Delete
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
[121] Fix | Delete
*
[122] Fix | Delete
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
[123] Fix | Delete
*
[124] Fix | Delete
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
[125] Fix | Delete
* @param string $packageName
[126] 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
[127] Fix | Delete
* @return bool
[128] Fix | Delete
*/
[129] Fix | Delete
public static function satisfies(VersionParser $parser, $packageName, $constraint)
[130] Fix | Delete
{
[131] Fix | Delete
$constraint = $parser->parseConstraints((string) $constraint);
[132] Fix | Delete
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
[133] Fix | Delete
[134] Fix | Delete
return $provided->matches($constraint);
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Returns a version constraint representing all the range(s) which are installed for a given package
[139] Fix | Delete
*
[140] Fix | Delete
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
[141] Fix | Delete
* whether a given version of a package is installed, and not just whether it exists
[142] Fix | Delete
*
[143] Fix | Delete
* @param string $packageName
[144] Fix | Delete
* @return string Version constraint usable with composer/semver
[145] Fix | Delete
*/
[146] Fix | Delete
public static function getVersionRanges($packageName)
[147] Fix | Delete
{
[148] Fix | Delete
foreach (self::getInstalled() as $installed) {
[149] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[150] Fix | Delete
continue;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
$ranges = array();
[154] Fix | Delete
if (isset($installed['versions'][$packageName]['pretty_version'])) {
[155] Fix | Delete
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
[156] Fix | Delete
}
[157] Fix | Delete
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
[158] Fix | Delete
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
[159] Fix | Delete
}
[160] Fix | Delete
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
[161] Fix | Delete
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
[162] Fix | Delete
}
[163] Fix | Delete
if (array_key_exists('provided', $installed['versions'][$packageName])) {
[164] Fix | Delete
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
return implode(' || ', $ranges);
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* @param string $packageName
[175] 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
[176] Fix | Delete
*/
[177] Fix | Delete
public static function getVersion($packageName)
[178] Fix | Delete
{
[179] Fix | Delete
foreach (self::getInstalled() as $installed) {
[180] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[181] Fix | Delete
continue;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
if (!isset($installed['versions'][$packageName]['version'])) {
[185] Fix | Delete
return null;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
return $installed['versions'][$packageName]['version'];
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* @param string $packageName
[196] 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
[197] Fix | Delete
*/
[198] Fix | Delete
public static function getPrettyVersion($packageName)
[199] Fix | Delete
{
[200] Fix | Delete
foreach (self::getInstalled() as $installed) {
[201] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[202] Fix | Delete
continue;
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
[206] Fix | Delete
return null;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
return $installed['versions'][$packageName]['pretty_version'];
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* @param string $packageName
[217] Fix | Delete
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
[218] Fix | Delete
*/
[219] Fix | Delete
public static function getReference($packageName)
[220] Fix | Delete
{
[221] Fix | Delete
foreach (self::getInstalled() as $installed) {
[222] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[223] Fix | Delete
continue;
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
if (!isset($installed['versions'][$packageName]['reference'])) {
[227] Fix | Delete
return null;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
return $installed['versions'][$packageName]['reference'];
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* @param string $packageName
[238] 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.
[239] Fix | Delete
*/
[240] Fix | Delete
public static function getInstallPath($packageName)
[241] Fix | Delete
{
[242] Fix | Delete
foreach (self::getInstalled() as $installed) {
[243] Fix | Delete
if (!isset($installed['versions'][$packageName])) {
[244] Fix | Delete
continue;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* @return array
[255] Fix | Delete
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
[256] Fix | Delete
*/
[257] Fix | Delete
public static function getRootPackage()
[258] Fix | Delete
{
[259] Fix | Delete
$installed = self::getInstalled();
[260] Fix | Delete
[261] Fix | Delete
return $installed[0]['root'];
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
/**
[265] Fix | Delete
* Returns the raw installed.php data for custom implementations
[266] Fix | Delete
*
[267] 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.
[268] Fix | Delete
* @return array[]
[269] Fix | Delete
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
[270] Fix | Delete
*/
[271] Fix | Delete
public static function getRawData()
[272] Fix | Delete
{
[273] 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);
[274] Fix | Delete
[275] Fix | Delete
if (null === self::$installed) {
[276] Fix | Delete
// only require the installed.php file if this file is loaded from its dumped location,
[277] Fix | Delete
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
[278] Fix | Delete
if (substr(__DIR__, -8, 1) !== 'C') {
[279] Fix | Delete
self::$installed = include __DIR__ . '/installed.php';
[280] Fix | Delete
} else {
[281] Fix | Delete
self::$installed = array();
[282] Fix | Delete
}
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
return self::$installed;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
/**
[289] Fix | Delete
* Returns the raw data of all installed.php which are currently loaded for custom implementations
[290] Fix | Delete
*
[291] Fix | Delete
* @return array[]
[292] Fix | Delete
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
[293] Fix | Delete
*/
[294] Fix | Delete
public static function getAllRawData()
[295] Fix | Delete
{
[296] Fix | Delete
return self::getInstalled();
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
/**
[300] Fix | Delete
* Lets you reload the static array from another file
[301] Fix | Delete
*
[302] Fix | Delete
* This is only useful for complex integrations in which a project needs to use
[303] Fix | Delete
* this class but then also needs to execute another project's autoloader in process,
[304] Fix | Delete
* and wants to ensure both projects have access to their version of installed.php.
[305] Fix | Delete
*
[306] Fix | Delete
* A typical case would be PHPUnit, where it would need to make sure it reads all
[307] Fix | Delete
* the data it needs from this class, then call reload() with
[308] Fix | Delete
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
[309] Fix | Delete
* the project in which it runs can then also use this class safely, without
[310] Fix | Delete
* interference between PHPUnit's dependencies and the project's dependencies.
[311] Fix | Delete
*
[312] Fix | Delete
* @param array[] $data A vendor/composer/installed.php data set
[313] Fix | Delete
* @return void
[314] Fix | Delete
*
[315] Fix | Delete
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
[316] Fix | Delete
*/
[317] Fix | Delete
public static function reload($data)
[318] Fix | Delete
{
[319] Fix | Delete
self::$installed = $data;
[320] Fix | Delete
self::$installedByVendor = array();
[321] Fix | Delete
[322] Fix | Delete
// when using reload, we disable the duplicate protection to ensure that self::$installed data is
[323] Fix | Delete
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
[324] Fix | Delete
// so we have to assume it does not, and that may result in duplicate data being returned when listing
[325] Fix | Delete
// all installed packages for example
[326] Fix | Delete
self::$installedIsLocalDir = false;
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
/**
[330] Fix | Delete
* @return string
[331] Fix | Delete
*/
[332] Fix | Delete
private static function getSelfDir()
[333] Fix | Delete
{
[334] Fix | Delete
if (self::$selfDir === null) {
[335] Fix | Delete
self::$selfDir = strtr(__DIR__, '\\', '/');
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
return self::$selfDir;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* @return array[]
[343] Fix | Delete
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
[344] Fix | Delete
*/
[345] Fix | Delete
private static function getInstalled()
[346] Fix | Delete
{
[347] Fix | Delete
if (null === self::$canGetVendors) {
[348] Fix | Delete
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
$installed = array();
[352] Fix | Delete
$copiedLocalDir = false;
[353] Fix | Delete
[354] Fix | Delete
if (self::$canGetVendors) {
[355] Fix | Delete
$selfDir = self::getSelfDir();
[356] Fix | Delete
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
[357] Fix | Delete
$vendorDir = strtr($vendorDir, '\\', '/');
[358] Fix | Delete
if (isset(self::$installedByVendor[$vendorDir])) {
[359] Fix | Delete
$installed[] = self::$installedByVendor[$vendorDir];
[360] Fix | Delete
} elseif (is_file($vendorDir.'/composer/installed.php')) {
[361] Fix | Delete
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
[362] Fix | Delete
$required = require $vendorDir.'/composer/installed.php';
[363] Fix | Delete
self::$installedByVendor[$vendorDir] = $required;
[364] Fix | Delete
$installed[] = $required;
[365] Fix | Delete
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
[366] Fix | Delete
self::$installed = $required;
[367] Fix | Delete
self::$installedIsLocalDir = true;
[368] Fix | Delete
}
[369] Fix | Delete
}
[370] Fix | Delete
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
[371] Fix | Delete
$copiedLocalDir = true;
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
if (null === self::$installed) {
[377] Fix | Delete
// only require the installed.php file if this file is loaded from its dumped location,
[378] Fix | Delete
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
[379] Fix | Delete
if (substr(__DIR__, -8, 1) !== 'C') {
[380] Fix | Delete
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
[381] Fix | Delete
$required = require __DIR__ . '/installed.php';
[382] Fix | Delete
self::$installed = $required;
[383] Fix | Delete
} else {
[384] Fix | Delete
self::$installed = array();
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
if (self::$installed !== array() && !$copiedLocalDir) {
[389] Fix | Delete
$installed[] = self::$installed;
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
return $installed;
[393] Fix | Delete
}
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function