Skip to content

Commit dd89411

Browse files
committed
Add documentation [skip ci]
1 parent 7e0f24f commit dd89411

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
11
# php-semver
2-
Semantic version parser and comparator for PHP
2+
[![Build Status](https://travis-ci.com/z4kn4fein/php-semver.svg?branch=master)](https://travis-ci.com/z4kn4fein/php-semver)
3+
[![Coverage Status](https://img.shields.io/codecov/c/github/z4kn4fein/php-semver.svg)](https://codecov.io/gh/z4kn4fein/php-semver)
4+
[![Latest Stable Version](https://poser.pugx.org/z4kn4fein/php-semver/version)](https://packagist.org/packages/z4kn4fein/php-semver)
5+
[![Total Downloads](https://poser.pugx.org/z4kn4fein/php-semver/downloads)](https://packagist.org/packages/z4kn4fein/php-semver)
6+
[![Latest Unstable Version](https://poser.pugx.org/z4kn4fein/php-semver/v/unstable)](https://packagist.org/packages/z4kn4fein/php-semver)
7+
8+
Semantic version utility library with parser and comparator written in PHP. It provides full support for the [semver 2.0.0](https://semver.org/spec/v2.0.0.html) standards.
9+
10+
## Requirements
11+
[PHP](https://www.php.net/) >= 5.5
12+
13+
## Installation with [Composer](https://getcomposer.org/)
14+
```shell
15+
composer require z4kn4fein/php-semver
16+
```
17+
18+
## Usage
19+
#### Parsing and available properties
20+
```php
21+
<?php
22+
23+
use z4kn4fein\SemVer\Version;
24+
25+
$version = Version::parse('2.5.6-alpha.12+build.34');
26+
27+
echo $version->getMajor(); // 2
28+
echo $version->getMinor(); // 5
29+
echo $version->getPatch(); // 6
30+
echo $version->getPreRelease(); // alpha.12
31+
echo $version->getBuildMeta(); // build.34
32+
echo $version->getVersionString(); // 2.5.6-alpha.12+build.34
33+
```
34+
#### Compare two versions
35+
```php
36+
<?php
37+
38+
use z4kn4fein\SemVer\Version;
39+
40+
// with static methods
41+
echo Version::lessThan('2.3.4', '2.4.1'); // true
42+
echo Version::lessThanOrEqual('2.4.1', '2.4.1'); // true
43+
echo Version::greaterThan('2.3.1-alpha.5', '2.3.1-alpha.3'); // true
44+
echo Version::greaterThanOrEqual('3.2.3','3.2.2'); // true
45+
echo Version::equal('3.2.3','3.2.3+build.3'); // true
46+
47+
// with instance methods
48+
$version = Version::parse('2.5.6-alpha.12+build.34');
49+
50+
echo $version->isLessThan('2.3.1'); // false
51+
echo $version->isLessThanOrEqual('2.5.6-alpha.15'); // true
52+
echo $version->isGreaterThan('2.5.6'); // false
53+
echo $version->isLessThanOrEqual('2.5.6-alpha.12'); // true
54+
echo $version->isEqual('2.5.6-alpha.12+build.56'); // true
55+
```
56+
## Invalid version handling
57+
When the version parsing fails due to an invalid format, the library throws a specific `VersionFormatException`.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "z4kn4fein/php-semver",
33
"type": "library",
4-
"description": "Semantic version parser and comparator for PHP.",
4+
"description": "Semantic version utility library with parser and comparator written in PHP. It provides full support for the semver 2.0.0 standards.",
55
"minimum-stability": "stable",
66
"keywords": ["Semantic version", "semver", "semver-parsing", "semver-compare"],
77
"homepage": "https://github.com/z4kn4fein/php-semver",

0 commit comments

Comments
 (0)