Ejemplo n.º 1
0
 /**
  * @param mixed $value
  * @return int
  */
 protected function sanitizeValue($value)
 {
     if (is_int($value) || ctype_digit($value)) {
         return (int) $value;
     }
     throw SemverException::format('"%s" is not a numeric version segment value', $value);
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $value
  * @return int|string
  */
 protected function sanitizeValue($value)
 {
     if (is_int($value) || ctype_digit($value)) {
         return (int) $value;
     } elseif (preg_match(self::REGEX_IDENTIFIER_ELEMENT, $value)) {
         return (string) $value;
     }
     throw SemverException::format('"%s" is not a valid version segment element', $value);
 }
Ejemplo n.º 3
0
 public function generate($operator, $data)
 {
     if (empty($operator)) {
         $operator = '=';
     }
     if (isset($this->generators[$operator])) {
         return forward_static_call_array($this->generators[$operator], $data);
     }
     throw SemverException::format('Unknown operator "%s"', $operator);
 }
Ejemplo n.º 4
0
 /**
  * @param string $simple
  * @return Primitive[] Collection of primitives matching the simple expression.
  */
 public static function parseSimpleExpression($simple)
 {
     if (!preg_match(self::REGEX_SIMPLE_EXPRESSION, $simple ?: '*', $parts)) {
         throw SemverException::format('Could not parse simple constraint "%s"', $simple);
     }
     $operator = $parts[1];
     $partial = str_replace(['*', 'x', 'X'], '*', $parts[3]);
     $qualifier = $parts[4];
     // Redirect leading wildcard into the universal wildcard primitive right away
     if ($partial[0] === '*') {
         return [Primitive::getWildcard()];
     }
     return PrimitiveGenerator::getInstance()->generate($operator, self::expandXRs($partial, $qualifier));
 }
Ejemplo n.º 5
0
 /**
  * Version constructor.
  *
  * @param string $version
  * @param int|bool $compliance Compliance level, or just false for loose
  * @throws SemverException in case of any parsing failures
  */
 public function __construct($version = self::DEFAULT_SEMVER, $compliance = self::COMPLIANCE_SEMVER2)
 {
     $version = (string) $version;
     $this->originalString = $version;
     if (!($parsed = VersionParser::parse($version, $issues))) {
         throw end($issues);
     }
     if ($compliance != ($this->compliance = $parsed[VersionParser::COMPLIANCE]) && $compliance) {
         throw SemverException::format('Version "%s" is not of required compliance level', $version);
     }
     $this->version = new NumbersSegment($parsed[VersionParser::VERSION]);
     $this->prerelease = new PrereleaseSegment($parsed[VersionParser::PRERELEASE]);
     $this->build = new IdentifierSegment($parsed[VersionParser::BUILD]);
 }
Ejemplo n.º 6
0
 /**
  * @param VersionInterface $version
  * @return bool
  */
 public function matches(VersionInterface $version)
 {
     switch ($this->operator) {
         case self::OPERATOR_EQ:
             return $this->negate xor $version->equals($this->version);
         case self::OPERATOR_GT:
             return $this->negate xor $version->greaterThan($this->version);
         case self::OPERATOR_LT:
             return $this->negate xor $version->lessThan($this->version);
             // @codeCoverageIgnoreStart
         // @codeCoverageIgnoreStart
         default:
             throw SemverException::format('Invalid primitive operator "%s"', $this->operator);
     }
     // @codeCoverageIgnoreEnd
 }
Ejemplo n.º 7
0
 public static function parseLoose($version)
 {
     $numbers = $pre = $build = [];
     foreach (preg_split('/[\\.\\-]/', $version) as $element) {
         if (ctype_digit($element)) {
             if (empty($pre)) {
                 $numbers[] = (int) $element;
             } else {
                 $pre[] = (int) $element;
             }
         } else {
             $pre[] = $element;
         }
     }
     if (empty($numbers)) {
         throw SemverException::format('No usable version numbers detected in "%s"', $version);
     }
     return [self::COMPLIANCE => Version::COMPLIANCE_NONE, self::VERSION => $numbers, self::PRERELEASE => $pre, self::BUILD => $build];
 }