Search by

adachsoft / version-contract

Arkadiusz Adach

A PHP contract for stable semantic version values and version bump operations.

Package info

gitlab.com/a.adach/version-contract

Issues

pkg:composer/adachsoft/version-contract

Statistics

Installs: 7

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-10-09 20:58 UTC

This package is not auto-updated.

Last update: 2026-10-10 18:00:24 UTC


README

Version Contract is a small PHP library that defines a stable contract for reading and calculating semantic versions.

Features

  • Immutable MAJOR.MINOR.PATCH semantic version value object.
  • Explicit major, minor, and patch bump levels.
  • PHP interface for current-version retrieval and next-version calculation.
  • Language-neutral JSON Schema for version payloads and error codes.
  • PHP 8.3+ support with PSR-4 autoloading.

Installation

composer require adachsoft/version-contract

Usage

Create a validated semantic version:

use AdachSoft\VersionContract\ValueObject\SemanticVersion;

$version = new SemanticVersion('1.4.2');
echo $version->value; // 1.4.2

Implement VersionManagerInterface in an application-specific adapter:

use AdachSoft\VersionContract\Enum\VersionBumpLevelEnum;
use AdachSoft\VersionContract\ValueObject\SemanticVersion;
use AdachSoft\VersionContract\VersionManagerInterface;

final class ApplicationVersionManager implements VersionManagerInterface
{
    public function getCurrentVersion(): SemanticVersion
    {
        return new SemanticVersion('1.4.2');
    }

    public function getNextVersion(
        SemanticVersion $currentVersion,
        VersionBumpLevelEnum $bumpLevel,
    ): SemanticVersion {
        // Calculate the next version using the selected bump level.
        return $currentVersion;
    }
}

The interface leaves version-source access and bump calculation to the integrating application. This keeps the contract independent from Git, Composer, package registries, and deployment tooling.

JSON Schema

The language-neutral contract is available at spec/version-contract.schema.json. It describes semantic version values, version bump requests, successful responses, and supported error codes.

Documentation

License

This library is released under the MIT License.