class Semver
Hierarchy
- class \Composer\Semver\Semver
Expanded class hierarchy of Semver
9 files declare their use of Semver
- AnnounceFetcher.php in core/
modules/ announcements_feed/ src/ AnnounceFetcher.php - ComposerInspector.php in core/
modules/ package_manager/ src/ ComposerInspector.php - ComposerMinimumStabilityValidator.php in core/
modules/ package_manager/ src/ Validator/ ComposerMinimumStabilityValidator.php - ComposerPatchesValidator.php in core/
modules/ package_manager/ src/ Validator/ ComposerPatchesValidator.php - ComposerPluginsValidator.php in core/
modules/ package_manager/ src/ Validator/ ComposerPluginsValidator.php
File
-
vendor/
composer/ semver/ src/ Semver.php, line 16
Namespace
Composer\SemverView source
class Semver {
const SORT_ASC = 1;
const SORT_DESC = -1;
/** @var VersionParser */
private static $versionParser;
/**
* Determine if given version satisfies given constraints.
*
* @param string $version
* @param string $constraints
*
* @return bool
*/
public static function satisfies($version, $constraints) {
if (null === self::$versionParser) {
self::$versionParser = new VersionParser();
}
$versionParser = self::$versionParser;
$provider = new Constraint('==', $versionParser->normalize($version));
$parsedConstraints = $versionParser->parseConstraints($constraints);
return $parsedConstraints->matches($provider);
}
/**
* Return all versions that satisfy given constraints.
*
* @param string[] $versions
* @param string $constraints
*
* @return string[]
*/
public static function satisfiedBy(array $versions, $constraints) {
$versions = array_filter($versions, function ($version) use ($constraints) {
return Semver::satisfies($version, $constraints);
});
return array_values($versions);
}
/**
* Sort given array of versions.
*
* @param string[] $versions
*
* @return string[]
*/
public static function sort(array $versions) {
return self::usort($versions, self::SORT_ASC);
}
/**
* Sort given array of versions in reverse.
*
* @param string[] $versions
*
* @return string[]
*/
public static function rsort(array $versions) {
return self::usort($versions, self::SORT_DESC);
}
/**
* @param string[] $versions
* @param int $direction
*
* @return string[]
*/
private static function usort(array $versions, $direction) {
if (null === self::$versionParser) {
self::$versionParser = new VersionParser();
}
$versionParser = self::$versionParser;
$normalized = array();
// Normalize outside of usort() scope for minor performance increase.
// Creates an array of arrays: [[normalized, key], ...]
foreach ($versions as $key => $version) {
$normalizedVersion = $versionParser->normalize($version);
$normalizedVersion = $versionParser->normalizeDefaultBranch($normalizedVersion);
$normalized[] = array(
$normalizedVersion,
$key,
);
}
usort($normalized, function (array $left, array $right) use ($direction) {
if ($left[0] === $right[0]) {
return 0;
}
if (Comparator::lessThan($left[0], $right[0])) {
return -$direction;
}
return $direction;
});
// Recreate input array, using the original indexes which are now in sorted order.
$sorted = array();
foreach ($normalized as $item) {
$sorted[] = $versions[$item[1]];
}
return $sorted;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Semver::$versionParser | private static | property | @var VersionParser |
Semver::rsort | public static | function | Sort given array of versions in reverse. |
Semver::satisfiedBy | public static | function | Return all versions that satisfy given constraints. |
Semver::satisfies | public static | function | Determine if given version satisfies given constraints. |
Semver::sort | public static | function | Sort given array of versions. |
Semver::SORT_ASC | constant | ||
Semver::SORT_DESC | constant | ||
Semver::usort | private static | function |