function InstalledVersions::getVersionRanges
Same name in this branch
- 11.1.x vendor/composer/composer/src/Composer/InstalledVersions.php \Composer\InstalledVersions::getVersionRanges()
Returns a version constraint representing all the range(s) which are installed for a given package
It is easier to use this via isInstalled() with the $constraint argument if you need to check whether a given version of a package is installed, and not just whether it exists
Parameters
string $packageName:
Return value
string Version constraint usable with composer/semver
2 calls to InstalledVersions::getVersionRanges()
- InstalledVersions::satisfies in vendor/
composer/ InstalledVersions.php - Checks whether the given package satisfies a version constraint
- InstalledVersions::satisfies in vendor/
composer/ composer/ src/ Composer/ InstalledVersions.php - Checks whether the given package satisfies a version constraint
File
-
vendor/
composer/ InstalledVersions.php, line 142
Class
- InstalledVersions
- This class is copied in every Composer installed project and available to all
Namespace
ComposerCode
public static function getVersionRanges($packageName) {
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}