Undo addition of initializeInstalled and remove inline copy of the data from the class

main
Jordi Boggiano 3 years ago
parent 3fe4f84a76
commit 82cffa17d3
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -24,15 +24,10 @@ use Composer\Semver\VersionParser;
*/ */
class InstalledVersions class InstalledVersions
{ {
private static $installed = array(); private static $installed;
private static $canGetVendors; private static $canGetVendors;
private static $installedByVendor = array(); private static $installedByVendor = array();
/**
* Initialize $installed array
*/
public static function initializeInstalled() {}
/** /**
* Returns a list of all package names which are present, either by being installed, replaced or provided * Returns a list of all package names which are present, either by being installed, replaced or provided
* *
@ -253,6 +248,10 @@ class InstalledVersions
{ {
@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); @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) {
self::$installed = include __DIR__ . '/installed.php';
}
return self::$installed; return self::$installed;
} }
@ -260,7 +259,7 @@ class InstalledVersions
* Returns the raw data of all installed.php which are currently loaded for custom implementations * Returns the raw data of all installed.php which are currently loaded for custom implementations
* *
* @return array[] * @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[]}, versions: array<string, array{pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[]}>}> * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}>
*/ */
public static function getAllRawData() public static function getAllRawData()
{ {
@ -309,14 +308,18 @@ class InstalledVersions
$installed[] = self::$installedByVendor[$vendorDir]; $installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) { } elseif (is_file($vendorDir.'/composer/installed.php')) {
$installed[] = self::$installedByVendor[$vendorDir] = require $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) {
self::$installed = require __DIR__ . '/installed.php';
}
$installed[] = self::$installed; $installed[] = self::$installed;
return $installed; return $installed;
} }
} }
InstalledVersions::initializeInstalled();

@ -130,14 +130,9 @@ class FilesystemRepository extends WritableArrayRepository
if ($this->dumpVersions) { if ($this->dumpVersions) {
$versions = $this->generateInstalledVersions($installationManager, $installPaths, $devMode, $repoDir); $versions = $this->generateInstalledVersions($installationManager, $installPaths, $devMode, $repoDir);
$versionsCode = $this->dumpToPhpCode($versions);
$fs->filePutContentsIfModified($repoDir.'/installed.php', '<?php return ' . $versionsCode . ';'."\n"); $fs->filePutContentsIfModified($repoDir.'/installed.php', '<?php return ' . $this->dumpToPhpCode($versions) . ';'."\n");
$installedVersionsClass = file_get_contents(__DIR__.'/../InstalledVersions.php'); $installedVersionsClass = file_get_contents(__DIR__.'/../InstalledVersions.php');
// while not strictly needed since https://github.com/composer/composer/pull/9635 - we keep this for BC
// and overall broader compatibility with people that may not use Composer's ClassLoader. They can
// simply include InstalledVersions.php manually and have it working in a basic way.
$installedVersionsClass = str_replace('public static function initializeInstalled() {}', 'public static function initializeInstalled() {' . PHP_EOL . 'self::$installed = ' . $versionsCode . ';' . PHP_EOL . '}', $installedVersionsClass);
$fs->filePutContentsIfModified($repoDir.'/InstalledVersions.php', $installedVersionsClass); $fs->filePutContentsIfModified($repoDir.'/InstalledVersions.php', $installedVersionsClass);
\Composer\InstalledVersions::reload($versions); \Composer\InstalledVersions::reload($versions);

Loading…
Cancel
Save