@@ -10,18 +10,25 @@ The parser expects versions to be in the following format:
1010
1111This allows the use of a wide range of version strings. Some examples:
1212
13- - ` 1 `
14- - ` 1.1 `
15- - ` 1.1.5 `
16- - ` 1.145.147 `
17- - ` 1.1.5-rc1 `
18- - ` 1.1.5-beta `
19- - ` 1.1.5-beta2 `
20- - ` 1.1.5-BranchName `
21- - ` 1.1.5-BranchName-alpha2 `
22-
23- > NOTE: Hyphens are typically used as separators, but underscores
24- are acceptable as well. Spaces are not supported.
13+ - ` 1 `
14+ - ` 1.1 `
15+ - ` 1.1.5 `
16+ - ` 1.145.147 `
17+ - ` 1.1.5-rc1 `
18+ - ` 1.1.5-beta `
19+ - ` 1.1.5-beta2 `
20+ - ` 1.1.5-beta.42 `
21+ - ` 1.1.5-BranchName `
22+ - ` 1.1.5-BranchName-alpha2 `
23+ - ` 1.1.5 BranchName A2 ` _ Spaces are allowed_
24+ - ` 1.1.5 "Branch name" ` _ Quotes are stripped_
25+ - ` 1.1.5 (BranchName) / Alpha 2 ` _ Special characters are filtered out_
26+ - ` 1.1.5-DEV Branch Name ` _ Branch names after the tag type_
27+
28+ Most special characters are filtered out, which means that it is
29+ very lenient in what is passed to it. After the version number,
30+ anything that is not a tag qualifier (` beta ` , ` alpha ` , etc.) is
31+ considered the branch name.
2532
2633## Installation
2734
@@ -101,8 +108,8 @@ $normalized = $version->getTagVersion(); // 1.0.0-beta
101108
102109### Checking the tag type
103110
104- To check the release type, the shorthand methods ` isBeta() ` , ` isAlpha() ` and ` isReleaseCandidate() ` can be used.
105- See "Supported release tags" for details.
111+ To check the release type, the shorthand methods ` isBeta() ` , ` isAlpha() ` ,
112+ etc. can be used. See "Supported release tags" for details.
106113
107114``` php
108115use Mistralys\VersionParser\VersionParser;
@@ -169,21 +176,21 @@ $hasBranch = $version->hasBranch(); // true
169176$branchName = $version->getBranchName(); // Foobar
170177```
171178
172- Branch names may contain numbers, but no hyphens.
179+ Branch names may contain special characters. Quotes are filtered out:
173180
174181``` php
175182use Mistralys\VersionParser\VersionParser;
176183
177- $version = VersionParser::create('1.5.2-Foobar45 ');
184+ $version = VersionParser::create('1.5.2 "Foobar/42" ');
178185
179186$hasBranch = $version->hasBranch(); // true
180- $branchName = $version->getBranchName(); // Foobar45
187+ $branchName = $version->getBranchName(); // Foobar/42
181188```
182189
183190### Setting the separator character
184191
185- By default, the branch name and tag are separated with hyphens (` - ` ).
186- This can be adjusted to any character:
192+ By default, the branch name and tag are separated with hyphens (` - ` )
193+ when normalizing the version string. This can be adjusted to any character:
187194
188195``` php
189196use Mistralys\VersionParser\VersionParser;
@@ -201,18 +208,18 @@ Will output:
2012081.5.2_BranchName_alpha5
202209```
203210
204- ### Converting tag names to uppercase
211+ ### Converting tag types to uppercase
205212
206- By default, tag names are lowercased. They can be converted to
207- uppercase:
213+ By default, tag types are converted to lowercase when normalizing the
214+ version string. They can be switched to uppercase instead :
208215
209216``` php
210217use Mistralys\VersionParser\VersionParser;
211218
212219$version = VersionParser::create('1.5.2-BranchName-alpha5');
213220
214221echo $version
215- ->setUppercase ()
222+ ->setTagUppercase ()
216223 ->getTagVersion();
217224```
218225
@@ -227,10 +234,11 @@ Will output:
227234The parser will handle the following tags automatically, and assign
228235them a build number value:
229236
237+ - ` dev ` or ` snapshot ` - Development release, weight: ` 8 `
230238- ` alpha ` - Alpha release, weight: ` 6 `
231239- ` beta ` - Beta release, weight: ` 4 `
232240- ` rc ` - Release candidate, weight: ` 2 `
233- - ` snapshot ` - Code snapshot , weight: ` 0 `
241+ - ` patch ` - Patch/bugfix release , weight: ` 1 `
234242
235243This means that comparing the same version numbers with different
236244release tags will work. For example, ` 1.4-beta ` is considered a higher
@@ -251,19 +259,23 @@ they can be added so the parser recognizes them:
251259``` php
252260use Mistralys\VersionParser\VersionParser;
253261
254- VersionParser::registerTagType('foobar', 5);
262+ // The third parameter is the short variant of the tag type.
263+ VersionParser::registerTagType('foobar', 5, 'f');
255264
256265$version = VersionParser::create('1.0.5-foobar2');
266+ $short = VersionParser::create('1.0.5-F2');
257267
258268echo $version->getTagType(); // foobar
269+ echo $short->getTagType(); // foobar
259270```
260271
261272If you mix custom tag types and the standard ones, be careful with
262273the sorting weight you set for them, so they will be weighted correctly.
263274If needed, you can change the weight of the default types to make more
264275room.
265276
266- This for example resets them all, and inserts some new types:
277+ This for example resets the weights for some existing tag types, and
278+ inserts new ones:
267279
268280``` php
269281use Mistralys\VersionParser\VersionParser;
0 commit comments