/** * Replaces the special range "^". * * @param SemverConverter $converter The semver converter * @param string $match The match version * * @return string the new match version */ public static function replaceSpecialRange(SemverConverter $converter, $match) { $newMatch = $converter->convertVersion($match); $newMatch = '>=' . static::standardizeVersion(SemverUtil::replaceAlias($newMatch, '>')) . ',<'; $exp = static::getSplittedVersion($match); $increase = false; foreach ($exp as $i => $sub) { if (static::analyzeSubVersion($i, $exp, $increase)) { continue; } static::increaseSubVersion($i, $exp, $increase); } $newMatch .= $converter->convertVersion(static::standardizeVersion($exp)); return $newMatch; }
/** * Step2: Converts the token of the matched range. * * @param int $i * @param string $match * @param array $matches * @param string|null $special * @param string|null $replace */ protected function matchRangeTokenStep2($i, $match, array &$matches, &$special, &$replace) { if (' ' === $match) { $matches[$i] = ','; } elseif ('||' === $match) { $matches[$i] = '|'; } elseif (in_array($special, array('^'))) { $matches[$i] = SemverRangeUtil::replaceSpecialRange($this, $match); $special = null; } else { $match = '~' === $special ? str_replace(array('*', 'x', 'X'), '0', $match) : $match; $matches[$i] = $this->convertVersion($match); $matches[$i] = $replace ? SemverUtil::replaceAlias($matches[$i], $replace) : $matches[$i]; $special = null; $replace = null; } }
/** * Step5: Converts the token of the matched range. * * @param int $i * @param string $match * @param array $matches * @param string|null $special * @param string|null $replace */ protected function matchRangeTokenStep5($i, $match, array &$matches, &$special, &$replace) { $matches[$i] = $this->convertVersion($match); $matches[$i] = $replace ? SemverUtil::replaceAlias($matches[$i], $replace) : $matches[$i]; $special = null; $replace = null; }
/** * Replaces the special range "~". * * @param string $match The match version * @param bool $majorVersion Limit the the major version or * * @return string the new match version */ protected function replaceSpecialRange($match, $majorVersion = false) { $newMatch = $this->convertVersion($match); $newMatch = '>='.SemverUtil::replaceAlias($newMatch, '>').',<'; $exp = explode('.', $match); $upVersion = isset($exp[0]) ? $exp[0] : '0'; if (!$majorVersion) { $minor = isset($exp[1]) ? (int) $exp[1] : 0; $upVersion .= '.' . ($minor + 1); } else { $upVersion = ((int) $upVersion + 1) . '.0'; } $newMatch .= $this->convertVersion($upVersion); return $newMatch; }