1 | <?php |
||
28 | final class HyphenatedRangeParser implements RangeParserInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var VersionBuilder |
||
32 | */ |
||
33 | private $versionBuilder; |
||
34 | |||
35 | /** |
||
36 | * @var ComparatorInterface |
||
37 | */ |
||
38 | private $greaterOrEqualTo; |
||
39 | |||
40 | /** |
||
41 | * @var ComparatorInterface |
||
42 | */ |
||
43 | private $lessThan; |
||
44 | |||
45 | /** |
||
46 | * @var ComparatorInterface |
||
47 | */ |
||
48 | private $lessOrEqualTo; |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Constructor. |
||
53 | * |
||
54 | * @param VersionBuilder $versionBuilder |
||
55 | * @param ComparatorInterface $greaterOrEqualTo |
||
56 | * @param ComparatorInterface $lessThan |
||
57 | * @param ComparatorInterface $lessOrEqualTo |
||
58 | */ |
||
59 | 11 | public function __construct( |
|
70 | |||
71 | /** |
||
72 | * Returns true if the token list can be parsed as a hyphenated range. |
||
73 | * |
||
74 | * @param Token[] $tokenList |
||
75 | * |
||
76 | * @return boolean |
||
77 | */ |
||
78 | 11 | public function canParse(array $tokenList) |
|
79 | { |
||
80 | $validConfigurations = [ |
||
81 | 11 | [Token::DIGITS, Token::DIGITS], |
|
82 | 11 | [Token::DIGITS, Token::LABEL_STRING, Token::DIGITS], |
|
83 | 11 | [Token::DIGITS, Token::DIGITS, Token::LABEL_STRING], |
|
84 | 11 | [Token::DIGITS, Token::LABEL_STRING, Token::DIGITS, Token::LABEL_STRING] |
|
85 | 11 | ]; |
|
86 | |||
87 | 11 | $isRange = false; |
|
88 | 11 | $chunkedList = $this->chunk($tokenList); |
|
89 | 11 | foreach ($validConfigurations as $configuration) { |
|
90 | 11 | $isRange = $isRange || $this->chunksMatchConfiguration($chunkedList, $configuration); |
|
91 | 11 | } |
|
92 | |||
93 | 11 | return $isRange; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Returns true if the provided token |
||
98 | * |
||
99 | * @param Token[][] $chunkedList |
||
100 | * @param string[] $configuration |
||
101 | * |
||
102 | * @return boolean |
||
103 | */ |
||
104 | 11 | private function chunksMatchConfiguration( |
|
118 | |||
119 | /** |
||
120 | * Build a ComparatorVersion representing the hyphenated range. |
||
121 | * |
||
122 | * @param Token[] $tokenList |
||
123 | * |
||
124 | * @return VersionRangeInterface |
||
125 | */ |
||
126 | 10 | public function parse(array $tokenList) |
|
172 | |||
173 | /** |
||
174 | * Chuck the tokens, splitting on hyphen. |
||
175 | * |
||
176 | * @param Token[] $tokenList |
||
177 | * |
||
178 | * @return Token[][] |
||
179 | */ |
||
180 | 11 | private function chunk(array $tokenList) |
|
205 | |||
206 | /** |
||
207 | * Determines the correct lower version constraint for a hyphenated range. |
||
208 | * |
||
209 | * @param Token[] $versionTokenList |
||
210 | * @param Token[] $labelTokenList |
||
211 | * |
||
212 | * @return VersionRangeInterface |
||
213 | */ |
||
214 | 6 | private function getLowerConstraint(array $versionTokenList, array $labelTokenList = []) |
|
221 | |||
222 | /** |
||
223 | * Determines the correct upper version constraint for a hyphenated range. |
||
224 | * |
||
225 | * @param Token[] $versionTokenList |
||
226 | * @param Token[] $labelTokenList |
||
227 | * |
||
228 | * @return VersionRangeInterface |
||
229 | */ |
||
230 | 6 | private function getUpperConstraint(array $versionTokenList, array $labelTokenList = []) |
|
267 | } |
||
268 |