Edit File by line

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