@@ -14,11 +14,15 @@ This allows the use of a wide range of version strings. Some examples:
1414 - 1.1
1515 - 1.1.5
1616 - 1.145.147
17+ - 1.1.5-rc1
1718 - 1.1.5-beta
1819 - 1.1.5-beta2
1920 - 1.1.5-BranchName
2021 - 1.1.5-BranchName-alpha2
2122
23+ > NOTE: Hyphens are typically used as separators, but underscores
24+ are acceptable as well. Spaces are not supported.
25+
2226## Installation
2327
2428Simply require the package with composer.
@@ -85,7 +89,8 @@ $normalized = $version->getTagVersion(); // 1.0.0-beta
8589
8690### Checking the tag type
8791
88- To check the release type, the shorthand methods ` isBeta() ` , ` isAlpha() ` and ` isReleaseCandidate() ` can be used.
92+ To check the release type, the shorthand methods ` isBeta() ` , ` isAlpha() ` and ` isReleaseCandidate() ` can be used.
93+ See "Supported release tags" for details.
8994
9095```
9196$version = VersionParser::create('1.5.2-beta');
@@ -149,3 +154,72 @@ $hasBranch = $version->hasBranch(); // true
149154$branchName = $version->getBranchName(); // Foobar45
150155```
151156
157+ ## Supported release tags
158+
159+ The parser will handle the following tags automatically, and assign
160+ them a build number value:
161+
162+ - ` alpha ` - Alpha release
163+ - ` beta ` - Beta release
164+ - ` rc ` - Release candidate
165+
166+ This means that comparing the same version numbers with different
167+ release tags will work. For example, ` 1.4-beta ` is considered a higher
168+ version than ` 1.4-alpha ` .
169+
170+ ### Numbering tags
171+
172+ Also supported is numbering tagged versions:
173+
174+ - ` 1.0-alpha ` - Implied ` alpha1 `
175+ - ` 1.0-alpha2 ` - Alpha ` 2 `
176+
177+ ## Build numbers
178+
179+ The version strings are intelligently converted to numbers, to allow
180+ comparisons and sorting. This includes the release tags like ` alpha `
181+ or ` beta ` , which are converted as well. The result is a build number
182+ which can be either a floating point number, or an integer.
183+
184+ > NOTE: These numbers are not meant to be human readable. Their sole
185+ purpose is to recognize version numbers programmatically.
186+
187+ There are two methods related to this:
188+
189+ ``` php
190+ use \Mistralys\VersionParser\VersionParser;
191+
192+ $version = VersionParser::create('1.0-alpha2');
193+
194+ $float = $version->getBuildNumber();
195+ $int = $version->getBuildNumberInt();
196+ ```
197+
198+ ## Sorting versions
199+
200+ The best way to sort versions is to use the build numbers, which allow
201+ numeric comparisons. Here's an example that sorts them in ascending order:
202+
203+ ``` php
204+ use \Mistralys\VersionParser\VersionParser;
205+
206+ $versions = array(
207+ VersionParser::create('1.1'),
208+ VersionParser::create('2'),
209+ VersionParser::create('1.5.9'),
210+ VersionParser::create('1.5.9-beta'),
211+ VersionParser::create('2.0.0-alpha')
212+ );
213+
214+ usort($versions, function (VersionParser $a, VersionParser $b) {
215+ return $a->getBuildNumberInt() - $b->getBuildNumberInt();
216+ });
217+ ```
218+
219+ This will sort the list the following way:
220+
221+ 1 . ` 1.1.0 `
222+ 2 . ` 1.5.9-beta `
223+ 3 . ` 1.5.9 `
224+ 4 . ` 2.0.0-alpha `
225+ 5 . ` 2.0.0 `
0 commit comments