KO
|
EN
gitlite — search
Search
#java
#game
#android
#python
#angular
#angularjs
#arduino
#c
#javascript
#ionic
#cpp
#nodejs
SemVer
★ 184
Open GitHub ↗
Semantic versioning helper library for PHP.
Download README (.md)
Explore Similar Repositories
MPMessagePack
:
MessagePack implementation for Objective-C / msgpack.org[Objective-C]
jquery-ui-daterangepicker
:
A JQuery UI based date range picker.
OpalImagePicker
:
A multiple image picker for iOS, written in Swift
codecov-python
:
Python report uploader for Codecov
error-message-catalog
:
A catalog of broken Elm programs / data to improve error messages
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
SemVer
?
Download (.md)
SemVer ====== <p align="center"> <img src="semver.png" alt="SemVer" width="50%"> </p> <p align="center"> <a href="http://semver.org">Semantic versioning</a> helper library • Created by <a href="https://www.ChrisKankiewicz.com">Chris Kankiewicz</a> (<a href="https://bsky.app/profile/phlak.dev">@phlak.dev</a>) </p> <p align="center"> <a href="https://github.com/PHLAK/SemVer/discussions"><img src="https://img.shields.io/badge/Join_the-Community-7b16ff.svg?style=for-the-badge" alt="Join our Community"></a> <a href="https://github.com/users/PHLAK/sponsorship"><img src="https://img.shields.io/badge/Become_a-Sponsor-cc4195.svg?style=for-the-badge" alt="Become a Sponsor"></a> <a href="https://paypal.me/ChrisKankiewicz"><img src="https://img.shields.io/badge/Make_a-Donation-006bb6.svg?style=for-the-badge" alt="One-time Donation"></a> <br> <a href="https://packagist.org/packages/PHLAK/SemVer"><img src="https://img.shields.io/packagist/v/PHLAK/SemVer.svg?style=flat-square" alt="Latest Stable Version"></a> <a href="https://packagist.org/packages/PHLAK/SemVer"><img src="https://img.shields.io/packagist/dt/PHLAK/SemVer.svg?style=flat-square" alt="Total Downloads"></a> <a href="https://packagist.org/packages/PHLAK/SemVer"><img src="https://img.shields.io/packagist/l/PHLAK/SemVer.svg?style=flat-square" alt="License"></a> <a href="https://github.com/PHLAK/SemVer/actions"><img src="https://img.shields.io/github/actions/workflow/status/PHLAK/SemVer/test-suite.yaml?style=flat-square&label=tests" alt="Tests Status"></a> </p> --- Requirements ------------ - [PHP](https://php.net) >= 8.1 Installation ------------ ```bash composer require phlak/semver ``` Initializing ------------ ```php use PHLAK\SemVer; $version = new SemVer\Version(); // Initilializes to '0.1.0' ``` Or initialize with a custom version by passing a version string on creation. Accepts any valid semantic version string with or without a preceding `v`. ```php $version = new SemVer\Version('v1.2.3-alpha.5+sha.8d31ff4'); ``` Or parse an incomple version string with the static `Version::parse()` constructor. ```php $version = SemVer\Version::parse('v1') // Initializes to '1.0.0' $version = SemVer\Version::parse('v1.2') // Initializes to '1.2.0' ``` Usage ----- #### Retrieve the version or individual values ```php $version = new SemVer\Version('v1.2.3-beta.4+007'); echo $version; // '1.2.3-beta.4+007' echo $version->major; // 1 echo $version->minor; // 2 echo $version->patch; // 3 echo $version->preRelease; // 'beta.4' echo $version->build; // '007' ``` #### Increment the version ```php $version = new SemVer\Version('v1.2.3'); $version->incrementMajor(); // v1.2.3 -> v2.0.0 $version->incrementMinor(); // v1.2.3 -> v1.3.0 $version->incrementPatch(); // v1.2.3 -> v1.2.4 $version->incrementPreRelease(); // v1.2.3-alpha.5 -> v1.2.3-alpha.6 ``` #### Set (override) the version or individual values ```php $version = new SemVer\Version(); $version->setVersion('v1.2.3'); // v1.2.3 $version->setMajor(3); // v1.2.3 -> v3.0.0 $version->setMinor(5); // v1.2.3 -> v1.5.0 $version->setPatch(7); // v1.2.3 -> 1.2.7 $version->setPreRelease('rc.2'); // v1.2.3 -> v1.2.3-rc.2 $version->setBuild('007'); // v1.2.3 -> v1.2.3+007 ``` #### Clear pre-release / build values ```php $version->setPreRelease(null); // v1.2.3-rc.2 -> v1.2.3 $version->setBuild(null); // v1.2.3+007 -> v1.2.3 ``` #### Check for pre-release / build values ```php $version->isPreRelease(); $version->hasBuild(); ``` #### Compare two SemVer objects ```php $version1 = new SemVer\Version('v1.2.3'); $version2 = new SemVer\Version('v3.2.1'); $version1->gt($version2); // false $version1->lt($version2); // true $version1->eq($version2); // false $version1->neq($version2); // true $version1->gte($version2); // false $version1->lte($version2); // true ``` ##### Limit comparison to the major version only Ignores the minor, patch and pre-release versions completely ```php $version1 = new SemVer\Version('v1.2.3-alpha.4'); $version2 = new SemVer\Version('v1.3.4-alpha.5'); $version1->gt($version2, Compare::MAJOR); // false $version1->lt($version2, Compare::MAJOR); // false $version1->eq($version2, Compare::MAJOR); // true $version1->neq($version2, Compare::MAJOR); // false $version1->gte($version2, Compare::MAJOR); // true $version1->lte($version2, Compare::MAJOR); // true ``` ##### Limit comparison to the major and minor versions only Ignores the patch and pre-release versions completely ```php $version1 = new SemVer\Version('v1.2.3-alpha.4'); $version2 = new SemVer\Version('v1.2.4-alpha.5'); $version1->gt($version2, Compare::MINOR); // false $version1->lt($version2, Compare::MINOR); // false $version1->eq($version2, Compare::MINOR); // true $version1->neq($version2, Compare::MINOR); // false $version1->gte($version2, Compare::MINOR); // true $version1->lte($version2, Compare::MINOR); // true ``` ##### Limit comparison to the major, minor and patch versions only Ignores the pre-release version completely ```php $version1 = new SemVer\Version('v1.2.3-alpha.4'); $version2 = new SemVer\Version('v1.2.3-alpha.5'); $version1->gt($version2, Compare::PATCH); // false $version1->lt($version2, Compare::PATCH); // false $version1->eq($version2, Compare::PATCH); // true $version1->neq($version2, Compare::PATCH); // false $version1->gte($version2, Compare::PATCH); // true $version1->lte($version2, Compare::PATCH); // true ``` Troubleshooting --------------- For general help and support join our [GitHub Discussions](https://github.com/PHLAK/SemVer/discussions) or reach out on [Bluesky](https://bsky.app/profile/phlak.dev). Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/SemVer/issues). Copyright --------- This project is liscensed under the [MIT License](https://github.com/PHLAK/SemVer/blob/master/LICENSE).