adachsoft / version-contract
A PHP contract for stable semantic version values and version bump operations.
Requires
- php: ^8.3
Requires (Dev)
- adachsoft/php-code-style: ^0.7.1
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.7
- symplify/phpstan-rules: ^14.18
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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.PATCHsemantic 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.