Skip to content

Commit c11b2b8

Browse files
committed
Initial commit
0 parents  commit c11b2b8

15 files changed

+1073
-0
lines changed

.buildpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<buildpath>
3+
<buildpathentry kind="src" path="tests"/>
4+
<buildpathentry kind="src" path="src"/>
5+
<buildpathentry kind="src" path="vendor"/>
6+
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
7+
</buildpath>

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
composer.phar
2+
/vendor/
3+
4+
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
5+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6+
# composer.lock

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:37:"PHPUnit\Runner\DefaultTestResultCache":1028:{a:2:{s:7:"defects";a:12:{s:21:"ParseTest::test_parse";i:3;s:22:"ParseTest::test_getTag";i:4;s:26:"ParseTest::test_tag_hyphen";i:3;s:24:"ParseTest::test_tag_beta";i:3;s:25:"ParseTest::test_tag_alpha";i:3;s:36:"ParseTest::test_tag_releaseCandidate";i:3;s:21:"ParseTest::test_empty";i:4;s:29:"ParseTest::test_getBranchName";i:3;s:23:"ParseTest::test_invalid";i:4;s:27:"ParseTest::test_tooManyDots";i:4;s:27:"ParseTest::test_stripSpaces";i:4;s:25:"ParseTest::test_normalize";i:3;}s:5:"times";a:14:{s:21:"ParseTest::test_parse";d:0.004;s:22:"ParseTest::test_getTag";d:0.001;s:22:"ParseTest::test_no_tag";d:0;s:24:"ParseTest::test_tag_beta";d:0;s:25:"ParseTest::test_tag_alpha";d:0;s:36:"ParseTest::test_tag_releaseCandidate";d:0;s:26:"ParseTest::test_tag_hyphen";d:0;s:27:"ParseTest::test_tooManyDots";d:0;s:27:"ParseTest::test_stripSpaces";d:0;s:21:"ParseTest::test_empty";d:0;s:23:"ParseTest::test_invalid";d:0;s:29:"ParseTest::test_getBranchName";d:0;s:28:"ParseTest::test_shortVersion";d:0;s:25:"ParseTest::test_normalize";d:0;}}}

.project

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Version parser</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.wst.validation.validationbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.dltk.core.scriptbuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.php.core.PHPNature</nature>
26+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
include_path=0;/Version parser\u00050;/Version parser/vendor\u00050;/Version parser/src
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<fixed facet="php.component"/>
4+
<fixed facet="php.core.component"/>
5+
<installed facet="php.core.component" version="1"/>
6+
<installed facet="php.component" version="7.3"/>
7+
</faceted-project>

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Mistralys
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Version string parser for PHP
2+
3+
PHP utility used to parse application version strings, and retrieve information on the version, as well as convert it to a numeric build number (float or integer). Supports release tags like alpha, beta and reelease candidate, as well as custom branch names.
4+
5+
## Supported version strings
6+
7+
The parser expects versions to be in the following format:
8+
9+
`MajorVersion.MinorVersion.PatchVersion-BranchName-ReleaseTagNumber`
10+
11+
This allows the use of a wide range of version strings. Some examples:
12+
13+
- 1
14+
- 1.1
15+
- 1.1.5
16+
- 1.145.147
17+
- 1.1.5-beta
18+
- 1.1.5-beta2
19+
- 1.1.5-BranchName
20+
- 1.1.5-BranchName-alpha2
21+
22+
## Installation
23+
24+
Simply require the package with composer.
25+
26+
Via command line:
27+
28+
```
29+
composer require mistralys/version-parser
30+
```
31+
32+
Via composer.json:
33+
34+
```json
35+
"require": {
36+
"mistralys/version-parser": "dev-master"
37+
}
38+
```
39+
40+
## Usage
41+
42+
### Getting individual version numbers
43+
44+
```
45+
$version = VersionParser::create('1.5.2');
46+
47+
$major = $version->getMajorVersion(); // 1
48+
$minor = $version->getMinorVersion(); // 5
49+
$patch = $version->getPatchVersion(); // 2
50+
```
51+
52+
### Getting a version without tag
53+
54+
```
55+
$version = VersionParser::create('1.5.2-RC3');
56+
57+
$number = $version->getVersion(); // 1.5.2
58+
```
59+
60+
The version is normalized to show all three levels, even if they were not specified.
61+
62+
```
63+
$version = VersionParser::create('1');
64+
65+
$number = $version->getVersion(); // 1.0.0
66+
```
67+
68+
### Getting a short version
69+
70+
The method `getShortVersion()` retrieves a version string with the minimum possible levels.
71+
72+
```
73+
$version = VersionParser::create('1.0.0');
74+
75+
$number = $version->getVersion(); // 1
76+
```
77+
78+
### Getting the full version, normalized
79+
80+
```
81+
$version = VersionParser::create('1-BETA');
82+
83+
$normalized = $version->getTagVersion(); // 1.0.0-beta
84+
```
85+
86+
### Checking the tag type
87+
88+
To check the release type, the shorthand methods `isBeta()`, `isAlpha()` and `isReleaseCandidate()` can be used.
89+
90+
```
91+
$version = VersionParser::create('1.5.2-beta');
92+
93+
$isBeta = $version->isBeta(); // true
94+
```
95+
96+
Alternatively, it is possible to check the tag type manually.
97+
98+
```
99+
$version = VersionParser::create('1.5.2-beta5');
100+
101+
if($version->getTagType() === VersionParser::TAG_TYPE_BETA)
102+
{
103+
// is a beta version
104+
}
105+
```
106+
107+
### Getting the tag number
108+
109+
When no number is added to the tag, it is assumed that it is the tag #1.
110+
111+
```
112+
$version = VersionParser::create('1.5.2-beta');
113+
114+
$betaVersion = $version->getTagNumber(); // 1 (implicit)
115+
```
116+
117+
With a number added:
118+
119+
```
120+
$version = VersionParser::create('1.5.2-beta5');
121+
122+
$betaVersion = $version->getTagNumber(); // 5
123+
```
124+
125+
### Getting the branch name
126+
127+
```
128+
$version = VersionParser::create('1.5.2-Foobar');
129+
130+
$hasBranch = $version->hasBranch(); // true
131+
$branchName = $version->getBranchName(); // Foobar
132+
```
133+
134+
This also works in combination with a release tag:
135+
136+
```
137+
$version = VersionParser::create('1.5.2-Foobar-RC1');
138+
139+
$hasBranch = $version->hasBranch(); // true
140+
$branchName = $version->getBranchName(); // Foobar
141+
```
142+
143+
Branch names may contain numbers, but no hyphens.
144+
145+
```
146+
$version = VersionParser::create('1.5.2-Foobar45');
147+
148+
$hasBranch = $version->hasBranch(); // true
149+
$branchName = $version->getBranchName(); // Foobar45
150+
```
151+

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name" : "mistralys/version-parser",
3+
"description" : "Class used to parse version numbers.",
4+
"type" : "library",
5+
"license" : "",
6+
"authors" :
7+
[
8+
{
9+
"email" : "[email protected]",
10+
"name" : "Sebastian Mordziol",
11+
"role" : "Lead"
12+
}
13+
],
14+
"autoload" :
15+
{
16+
"psr-4" :
17+
{
18+
"Mistralys\\VersionParser\\" : "src/"
19+
},
20+
"classmap" :
21+
[
22+
"src/"
23+
]
24+
},
25+
"require-dev" :
26+
{
27+
"phpunit/phpunit" : ">=8.5",
28+
"phpstan/phpstan" : ">=0.12"
29+
},
30+
"minimum-stability" : "dev",
31+
"prefer-stable" : true
32+
}

0 commit comments

Comments
 (0)