PHPackages                             horde/version - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. horde/version

ActiveLibrary

horde/version
=============

Handle Semantic Version 2.0.0 format and similar semantic version formats

v1.0.0beta2(1mo ago)058↓100%1LGPL-2.1-onlyPHPPHP ^8.2CI failing

Since May 12Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/horde/Version)[ Packagist](https://packagist.org/packages/horde/version)[ Docs](https://www.horde.org)[ RSS](/packages/horde-version/feed)WikiDiscussions FRAMEWORK\_6\_0 Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (7)Used By (1)

horde/version
=============

[](#hordeversion)

Create, parse, increment, compare, and constrain strict SemVer V2 version tags and other common semantic versioning formats found in the wild.

Features
--------

[](#features)

- ✅ Parse strict SemVer 2.0 and relaxed variants
- ✅ Compare versions with full SemVer 2.0 precedence rules
- ✅ Generate next versions (patch/minor/major bumps)
- ✅ Detect and manage stability levels (dev/alpha/beta/rc/stable)
- ✅ Version constraints (Composer-compatible syntax)
- ✅ Collection utilities (sort, filter, find latest)
- ✅ Comprehensive test coverage (193 tests, 592 assertions)

Installation
------------

[](#installation)

```
composer require horde/version
```

Quick Start
-----------

[](#quick-start)

### Parsing Versions

[](#parsing-versions)

```
use Horde\Version\SemVerV2Version;
use Horde\Version\RelaxedSemanticVersion;

// Strict SemVer 2.0
$version = new SemVerV2Version('1.0.0');
$version = new SemVerV2Version('1.0.0-alpha.1+build.123');

// Relaxed format (prefixes, no hyphen, missing patch)
$version = new RelaxedSemanticVersion('v1.0.0');
$version = new RelaxedSemanticVersion('1.0');           // → 1.0.0
$version = new RelaxedSemanticVersion('1.0.0alpha1');   // → 1.0.0-alpha1

// Access components
echo $version->major;        // 1
echo $version->minor;        // 0
echo $version->patch;        // 0
echo $version->preRelease;   // 'alpha1'
echo $version->buildInfo;    // ''
```

### Comparing Versions

[](#comparing-versions)

```
use Horde\Version\SemVerV2Comparison;

$comparison = new SemVerV2Comparison();
$result = $comparison->compare(
    new SemVerV2Version('1.0.0'),
    new SemVerV2Version('2.0.0')
); // -1 (first < second)

// Or use helper methods
$v1 = new SemVerV2Version('1.0.0');
$v2 = new SemVerV2Version('2.0.0');

$v1->isLessThan($v2);      // true
$v2->isGreaterThan($v1);   // true
$v1->equals($v1);          // true
```

### Version Constraints

[](#version-constraints)

```
use Horde\Version\ConstraintParser;

$parser = new ConstraintParser();

// Exact match
$constraint = $parser->parse('1.0.0');
$constraint->isSatisfiedBy($version); // true if version == 1.0.0

// Comparison operators
$constraint = $parser->parse('>=1.0.0');
$constraint = $parser->parse('parse('^1.2.3');  // >=1.2.3 parse('^0.2.3');  // >=0.2.3 parse('^0.0.3');  // =0.0.3

// Tilde (~) - Allow patch-level changes
$constraint = $parser->parse('~1.2.3');  // >=1.2.3 parse('~1.2');    // >=1.2.0 parse('1.0.*');   // >=1.0.0 parse('1.*');     // >=1.0.0 parse('1.0.0 - 2.0.0');

// AND (space-separated)
$constraint = $parser->parse('>=1.0.0
