Regenerate Composer auto-loader

This commit is contained in:
Frédéric Guillot
2022-09-04 22:13:36 -07:00
parent 4f3fcfee75
commit 2aad3ec03e
28 changed files with 602 additions and 614 deletions

View File

@@ -18,13 +18,190 @@ use Composer\Semver\VersionParser;
/**
* This class is copied in every Composer installed project and available to all
*
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
*
* To require its presence, you can require `composer-runtime-api ^2.0`
* To require it's presence, you can require `composer-runtime-api ^2.0`
*/
class InstalledVersions
{
private static $installed;
private static $installed = array (
'root' =>
array (
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'aliases' =>
array (
),
'reference' => 'f3966c99fc2c3438c875e2ef7ff5fafecc6c8cd4',
'name' => 'kanboard/kanboard',
),
'versions' =>
array (
'christian-riesen/base32' =>
array (
'pretty_version' => '1.6.0',
'version' => '1.6.0.0',
'aliases' =>
array (
),
'reference' => '2e82dab3baa008e24a505649b0d583c31d31e894',
),
'christian-riesen/otp' =>
array (
'pretty_version' => '1.4.3',
'version' => '1.4.3.0',
'aliases' =>
array (
),
'reference' => '20a539ce6280eb029030f4e7caefd5709a75e1ad',
),
'erusev/parsedown' =>
array (
'pretty_version' => '1.7.4',
'version' => '1.7.4.0',
'aliases' =>
array (
),
'reference' => 'cb17b6477dfff935958ba01325f2e8a2bfa6dab3',
),
'kanboard/kanboard' =>
array (
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'aliases' =>
array (
),
'reference' => 'f3966c99fc2c3438c875e2ef7ff5fafecc6c8cd4',
),
'pimple/pimple' =>
array (
'pretty_version' => 'v3.5.0',
'version' => '3.5.0.0',
'aliases' =>
array (
),
'reference' => 'a94b3a4db7fb774b3d78dad2315ddc07629e1bed',
),
'psr/container' =>
array (
'pretty_version' => '2.0.2',
'version' => '2.0.2.0',
'aliases' =>
array (
),
'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963',
),
'psr/event-dispatcher-implementation' =>
array (
'provided' =>
array (
0 => '1.0',
),
),
'psr/log' =>
array (
'pretty_version' => '1.1.4',
'version' => '1.1.4.0',
'aliases' =>
array (
),
'reference' => 'd49695b909c3b7628b6289db5479a1c204601f11',
),
'psr/log-implementation' =>
array (
'provided' =>
array (
0 => '1.0|2.0',
),
),
'symfony/console' =>
array (
'pretty_version' => 'v4.4.37',
'version' => '4.4.37.0',
'aliases' =>
array (
),
'reference' => '0259f01dbf9d77badddbbf4c2abb681f24c9cac6',
),
'symfony/deprecation-contracts' =>
array (
'pretty_version' => 'v2.5.2',
'version' => '2.5.2.0',
'aliases' =>
array (
),
'reference' => 'e8b495ea28c1d97b5e0c121748d6f9b53d075c66',
),
'symfony/event-dispatcher' =>
array (
'pretty_version' => 'v4.4.37',
'version' => '4.4.37.0',
'aliases' =>
array (
),
'reference' => '3ccfcfb96ecce1217d7b0875a0736976bc6e63dc',
),
'symfony/event-dispatcher-contracts' =>
array (
'pretty_version' => 'v1.1.11',
'version' => '1.1.11.0',
'aliases' =>
array (
),
'reference' => '01e9a4efac0ee33a05dfdf93b346f62e7d0e998c',
),
'symfony/event-dispatcher-implementation' =>
array (
'provided' =>
array (
0 => '1.1',
),
),
'symfony/finder' =>
array (
'pretty_version' => 'v5.4.11',
'version' => '5.4.11.0',
'aliases' =>
array (
),
'reference' => '7872a66f57caffa2916a584db1aa7f12adc76f8c',
),
'symfony/polyfill-mbstring' =>
array (
'pretty_version' => 'v1.24.0',
'version' => '1.24.0.0',
'aliases' =>
array (
),
'reference' => '0abb51d2f102e00a4eefcf46ba7fec406d245825',
),
'symfony/polyfill-php73' =>
array (
'pretty_version' => 'v1.24.0',
'version' => '1.24.0.0',
'aliases' =>
array (
),
'reference' => 'cc5db0e22b3cb4111010e48785a97f670b350ca5',
),
'symfony/polyfill-php80' =>
array (
'pretty_version' => 'v1.26.0',
'version' => '1.26.0.0',
'aliases' =>
array (
),
'reference' => 'cfa0ae98841b9e461207c13ab093d76b0fa7bace',
),
'symfony/service-contracts' =>
array (
'pretty_version' => 'v1.1.2',
'version' => '1.1.2.0',
'aliases' =>
array (
),
'reference' => '191afdcb5804db960d26d8566b7e9a2843cab3a0',
),
),
);
private static $canGetVendors;
private static $installedByVendor = array();
@@ -41,6 +218,7 @@ class InstalledVersions
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
@@ -48,42 +226,19 @@ class InstalledVersions
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
/**
* Returns a list of all package names with a specific type e.g. 'library'
*
* @param string $type
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
/**
* Checks whether the given package is installed
*
* This also returns true if the package name is provided or replaced by another package
*
* @param string $packageName
* @param bool $includeDevRequirements
* @return bool
*/
public static function isInstalled($packageName, $includeDevRequirements = true)
public static function isInstalled($packageName)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
return true;
}
}
@@ -97,9 +252,10 @@ class InstalledVersions
*
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
*
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
* @param string $packageName
* @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
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
* @param string $packageName
* @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
*
* @return bool
*/
public static function satisfies(VersionParser $parser, $packageName, $constraint)
@@ -209,26 +365,9 @@ class InstalledVersions
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @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.
*/
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @return array
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[]}
*/
public static function getRootPackage()
{
@@ -240,38 +379,14 @@ class InstalledVersions
/**
* Returns the raw installed.php data for custom implementations
*
* @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.
* @return array[]
* @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}>}
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[]}, versions: list<string, array{pretty_version: ?string, version: ?string, aliases: ?string[], reference: ?string, replaced: ?string[], provided: ?string[]}>}
*/
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);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
/**
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @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}>}>
*/
public static function getAllRawData()
{
return self::getInstalled();
}
/**
* Lets you reload the static array from another file
*
@@ -288,7 +403,7 @@ class InstalledVersions
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @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
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[]}, versions: list<string, array{pretty_version: ?string, version: ?string, aliases: ?string[], reference: ?string, replaced: ?string[], provided: ?string[]}>} $data
*/
public static function reload($data)
{
@@ -298,7 +413,6 @@ class InstalledVersions
/**
* @return array[]
* @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}>}>
*/
private static function getInstalled()
{
@@ -309,27 +423,16 @@ class InstalledVersions
$installed = array();
if (self::$canGetVendors) {
// @phpstan-ignore-next-line
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';
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1];
}
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = require __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
$installed[] = self::$installed;
return $installed;