Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stevegrunwell/semver-parser
Library for parsing and manipulating Semantic Versioning ("SemVer") relases
https://github.com/stevegrunwell/semver-parser
composer-library composer-package php-library semver
Last synced: 2 months ago
JSON representation
Library for parsing and manipulating Semantic Versioning ("SemVer") relases
- Host: GitHub
- URL: https://github.com/stevegrunwell/semver-parser
- Owner: stevegrunwell
- License: mit
- Created: 2019-10-05T02:46:57.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-08-18T16:14:09.000Z (5 months ago)
- Last Synced: 2024-10-13T08:43:19.957Z (3 months ago)
- Topics: composer-library, composer-package, php-library, semver
- Language: PHP
- Homepage:
- Size: 67.4 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
## SemVer Parser
This library defines the `SteveGrunwell\SemVer\Version` class, which is meant to parse and manipulate version numbers based on [the rules of Semantic Versioning (a.k.a. "SemVer")](https://semver.org/).
## Installation
Install the library using [Composer](https://getcomposer.org/):
```sh
$ composer require stevegrunwell/semver-parser
```Please note that while this library should be compatible with PHP 7.4 and newer, the unit tests are only run in CI against [actively-supported versions of PHP](https://www.php.net/supported-versions.php).
## Usage
The constructor of the `Version` class can accept a valid, semantic version based on [the Semantic Versioning 2.0.0 specification](https://semver.org/spec/v2.0.0.html):
```php
use SteveGrunwell\SemVer\Parser;// Import the Composer-generated autoloader.
require_once __DIR__ . '/vendor/autoload.php';$version = new Version('1.2.3-rc1+local');
// Parse the version.
$version->getMajorVersion(); // 1
$version->getMinorVersion(); // 2
$version->getPatchVersion(); // 3
$version->getPreReleaseVersion(); // rc1
$version->getBuildMetadata(): // local// Modify the version.
$version->setMajorVersion(4);
$version->setMinorVersion(5);
$version->setPatchVersion(6);
$version->setPreReleaseVersion('rc2');
$version->setBuildMetadata('github-actions.ubuntu2404');// Retrieve the updated version as a string.
$version->getVersion(); // "4.5.6-rc2+github-actions.ubuntu2404"
(string) $version; // "4.5.6-rc2+github-actions.ubuntu2404"
```### Additional methods
In addition to the setters and getters described above, each of the major, minor, and patch values have corresponding increment and decrement methods:
```php
// Increment values.
$version->incrementMajorVersion();
$version->incrementMinorVersion();
$version->incrementPatchVersion();// Decrement values.
$version->decrementMajorVersion();
$version->decrementMinorVersion();
$version->decrementPatchVersion();
```It's worth noting that `incrementMajorVersion()` and `incrementMinorVersion()` will reset the the minor/patch and patch numbers (respectively) according to [the Semantic Versioning 2.0.0 specification](https://semver.org/spec/v2.0.0.html#spec-item-7).
## License
This library is released under the MIT License. Please see [LICENSE.md](LICENSE.md) for more details.