Ejemplo n.º 1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $comparatorFactory = new ComparatorFactory();
     $versionBuilder = new VersionBuilder(new LabelBuilder());
     $wildcardParser = new WildcardRangeParser($comparatorFactory->get('>='), $comparatorFactory->get('<'));
     $matcherList = array(new CaretRangeParser($comparatorFactory->get('>='), $comparatorFactory->get('<')), new TildeRangeParser($wildcardParser), $wildcardParser, new BranchParser($wildcardParser), new ComparatorVersionParser($comparatorFactory, $versionBuilder), new HyphenatedRangeParser($versionBuilder, $comparatorFactory->get('>='), $comparatorFactory->get('<'), $comparatorFactory->get('<=')));
     $this->tokenizer = new VersionTokenizer();
     $this->parser = new VersionParser($matcherList);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider tokenProvider
  */
 public function testParseRange($version, $tokenList, $expectedRange, $expectedSerialization)
 {
     $comparatorFactory = new ComparatorFactory();
     $versionBuilder = new VersionBuilder(new LabelBuilder());
     $wildcardParser = new WildcardRangeParser($comparatorFactory->get('>='), $comparatorFactory->get('<'));
     $matcherList = array(new CaretRangeParser($comparatorFactory->get('>='), $comparatorFactory->get('<')), new TildeRangeParser($wildcardParser), $wildcardParser, new BranchParser($wildcardParser), new ComparatorVersionParser($comparatorFactory, $versionBuilder), new HyphenatedRangeParser($versionBuilder, $comparatorFactory->get('>='), $comparatorFactory->get('<'), $comparatorFactory->get('<=')));
     $parser = new VersionParser($matcherList);
     $range = $parser->parseRange($tokenList);
     $this->assertEquals($expectedRange, $range);
     $this->assertEquals($expectedSerialization, strval($range));
 }
 /**
  * Build a ComparatorVersion representing the comparator & version.
  *
  * @param Token[] $tokenList
  *
  * @return VersionRangeInterface
  */
 public function parse(array $tokenList)
 {
     $comparatorList = array('<', '<=', '>', '>=', '=');
     // Prefixed comparator, hydrate & remove
     if (count($tokenList) > 0 && in_array($tokenList[0]->getValue(), $comparatorList)) {
         $comparator = $this->comparatorFactory->get($tokenList[0]->getValue());
         $tokenList = array_slice($tokenList, 1);
         // Default to equality
     } else {
         $comparator = $this->comparatorFactory->get('=');
     }
     $chunkList = $this->chunk($tokenList);
     $versionTokenList = $chunkList[0];
     $labelTokenList = array();
     if (count($chunkList) > 1) {
         $labelTokenList = $chunkList[1];
     }
     return new ComparatorVersion($comparator, $this->versionBuilder->buildFromTokens($versionTokenList, $labelTokenList));
 }