/** * @param string $expression * @return CompoundExpression */ public static function parseConjunctiveExpression($expression) { $result = new CompoundExpression(CompoundExpression::CONJUNCTIVE); if (preg_match(self::REGEX_HYPHEN, $expression, $parts)) { $result->addMultiple(self::parseHyphen($parts[1], $parts[2])); } else { foreach (preg_split('/\\s+/', $expression) as $simple) { $result->addMultiple(self::parseSimpleExpression($simple)); } } return $result; }
public function testCompoundExpression() { $expression = new CompoundExpression(CompoundExpression::DISJUNCTIVE, [new Primitive('1.0.0', Primitive::OPERATOR_EQ), '>2.3.4']); $this->assertTrue($expression->matches(Version::fromString('1.0.0'))); $this->assertTrue($expression->matches(Version::fromString('3.0.0'))); $this->assertTrue($expression->matches(Version::fromString('2.3.5'))); $this->assertFalse($expression->matches(Version::fromString('1.0.0-alpha'))); $this->assertFalse($expression->matches(Version::fromString('2.3.4'))); $this->assertFalse($expression->matches(Version::fromString('0.9.9'))); }
/** * @param VersionInterface $version * @return bool Whether the version is matches by this expression. */ public function matches(VersionInterface $version) { return $this->rootExpression->matches($version); }