diff --git a/src/Composer/InstalledVersions.php b/src/Composer/InstalledVersions.php index 81f4a6227..2c6c06f70 100644 --- a/src/Composer/InstalledVersions.php +++ b/src/Composer/InstalledVersions.php @@ -24,15 +24,10 @@ use Composer\Semver\VersionParser; */ class InstalledVersions { - private static $installed = array(); + private static $installed; private static $canGetVendors; 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 * @@ -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); + if (null === self::$installed) { + self::$installed = include __DIR__ . '/installed.php'; + } + return self::$installed; } @@ -260,7 +259,7 @@ class InstalledVersions * Returns the raw data of all installed.php which are currently loaded for custom implementations * * @return array[] - * @psalm-return list}> + * @psalm-return list}> */ public static function getAllRawData() { @@ -309,14 +308,18 @@ class InstalledVersions $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) { + self::$installed = require __DIR__ . '/installed.php'; + } $installed[] = self::$installed; return $installed; } } - -InstalledVersions::initializeInstalled(); diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index 6b44d97d9..a80777033 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -130,14 +130,9 @@ class FilesystemRepository extends WritableArrayRepository if ($this->dumpVersions) { $versions = $this->generateInstalledVersions($installationManager, $installPaths, $devMode, $repoDir); - $versionsCode = $this->dumpToPhpCode($versions); - $fs->filePutContentsIfModified($repoDir.'/installed.php', 'filePutContentsIfModified($repoDir.'/installed.php', 'dumpToPhpCode($versions) . ';'."\n"); $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); \Composer\InstalledVersions::reload($versions);