|
|
@@ -18,27 +18,71 @@ 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
|
|
|
{
|
|
|
- /**
|
|
|
- * @var mixed[]|null
|
|
|
- * @psalm-var 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}>}|array{}|null
|
|
|
- */
|
|
|
- private static $installed;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var bool|null
|
|
|
- */
|
|
|
+ private static $installed = array (
|
|
|
+ 'root' =>
|
|
|
+ array (
|
|
|
+ 'pretty_version' => 'dev-master',
|
|
|
+ 'version' => 'dev-master',
|
|
|
+ 'aliases' =>
|
|
|
+ array (
|
|
|
+ ),
|
|
|
+ 'reference' => 'f840cccb743ce7b66c811712f754210e71a67183',
|
|
|
+ 'name' => 'privatebin/privatebin',
|
|
|
+ ),
|
|
|
+ 'versions' =>
|
|
|
+ array (
|
|
|
+ 'jdenticon/jdenticon' =>
|
|
|
+ array (
|
|
|
+ 'pretty_version' => '1.0.2',
|
|
|
+ 'version' => '1.0.2.0',
|
|
|
+ 'aliases' =>
|
|
|
+ array (
|
|
|
+ ),
|
|
|
+ 'reference' => 'cabb7a44c413c318392a341c5d3ca30fcdd57a6f',
|
|
|
+ ),
|
|
|
+ 'mlocati/ip-lib' =>
|
|
|
+ array (
|
|
|
+ 'pretty_version' => '1.18.0',
|
|
|
+ 'version' => '1.18.0.0',
|
|
|
+ 'aliases' =>
|
|
|
+ array (
|
|
|
+ ),
|
|
|
+ 'reference' => 'c77bd0b1f3e3956c7e9661e75cb1f54ed67d95d2',
|
|
|
+ ),
|
|
|
+ 'paragonie/random_compat' =>
|
|
|
+ array (
|
|
|
+ 'pretty_version' => 'v2.0.21',
|
|
|
+ 'version' => '2.0.21.0',
|
|
|
+ 'aliases' =>
|
|
|
+ array (
|
|
|
+ ),
|
|
|
+ 'reference' => '96c132c7f2f7bc3230723b66e89f8f150b29d5ae',
|
|
|
+ ),
|
|
|
+ 'privatebin/privatebin' =>
|
|
|
+ array (
|
|
|
+ 'pretty_version' => 'dev-master',
|
|
|
+ 'version' => 'dev-master',
|
|
|
+ 'aliases' =>
|
|
|
+ array (
|
|
|
+ ),
|
|
|
+ 'reference' => 'f840cccb743ce7b66c811712f754210e71a67183',
|
|
|
+ ),
|
|
|
+ 'yzalis/identicon' =>
|
|
|
+ array (
|
|
|
+ 'pretty_version' => '2.0.0',
|
|
|
+ 'version' => '2.0.0.0',
|
|
|
+ 'aliases' =>
|
|
|
+ array (
|
|
|
+ ),
|
|
|
+ 'reference' => 'ff5ed090129cab9bfa2a322857d4a01d107aa0ae',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+);
|
|
|
private static $canGetVendors;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var array[]
|
|
|
- * @psalm-var array<string, 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 $installedByVendor = array();
|
|
|
|
|
|
/**
|
|
|
@@ -54,6 +98,7 @@ class InstalledVersions
|
|
|
$packages[] = array_keys($installed['versions']);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if (1 === \count($packages)) {
|
|
|
return $packages[0];
|
|
|
}
|
|
|
@@ -61,42 +106,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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -110,9 +132,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)
|
|
|
@@ -222,26 +245,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()
|
|
|
{
|
|
|
@@ -253,38 +259,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
|
|
|
*
|
|
|
@@ -301,7 +283,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)
|
|
|
{
|
|
|
@@ -311,7 +293,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()
|
|
|
{
|
|
|
@@ -322,27 +303,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;
|