herrera-io/version
PHP library for Semantic Versioning (SemVer 2.0.0): parse versions into a builder, increment major/minor/patch, edit pre-release/build metadata, validate formats, compare versions, and dump back to strings for release tooling.
Pros:
incrementMajor(), clearPreRelease()), critical for CI/CD pipelines, release automation, and feature flag management in Laravel applications.Version objects reduce side effects, fitting Laravel’s service-layer patterns (e.g., repositories, commands) where purity is desirable.alpha, beta) and build metadata (e.g., +commit-hash), useful for canary releases, rollback tracking, or artifact versioning in microservices.Cons:
create_function).PackageManifest, Artisan commands, or config() system.composer.json), a lightweight regex or Composer\Semver may suffice with less maintenance risk.$this->app->singleton(Herrera\Version\Parser::class);
$this->app->bind(Herrera\Version\Comparator::class);
Version::parse($string)).return_type declarations, intval behavior changes).schema_versions table, soft-deleted snapshots with versioned metadata).versions table and validate using Validator::isVersion()./updates?version=1.2.3).incrementPatch() in post-deploy hooks).$version = Parser::toBuilder(config('app.version'))
->incrementPatch()
->getVersion();
config(['app.version' => Dumper::toString($version)]);
#[ReturnTypeWillChange], fixing deprecated functions) requires deep codebase knowledge.composer.json "repositories" to avoid dependency conflicts.class LaravelVersionService {
public function parse(string $version): Version {
try {
return Parser::toVersion($version);
} catch (Exception $e) {
// Fallback: Regex parsing or throw custom exception
}
}
}
php-semver/php-semver or ramsey/uuid if forking fails.Composer\Semver or php-semver/php-semver?
Composer\Semver is heavier and tied to Composer; this package offers a lighter, more flexible API with builder patterns.php-semver/php-semver is more actively maintained but lacks the builder/immutable design.explode('.', $version) + regex for basic validation).Artisan::version())?
Artisan::version() is for CLI tooling.php-semver/php-semver or a custom solution if forking fails. Document the migration path in UPGRADE.md.PackageManifest?
composer.json or custom manifest files, but avoid replacing Laravel’s core package resolution.Composer\Semver to ensure acceptable latency.incrementPatch() in GitHub Actions).1.2.0-beta.1) for canary testing.npm version or go-mod-version).2023.10.1).Version classes or regex parsing.ReleaseCommand:
// Before
$current = explode('.', config('app.version'));
if ($current[0] < 2) { /* ... */ }
// After
$version = Parser::toVersion(config('app.version'));
if (Comparator::isLessThan($version, Parser::toVersion('2.0.0'))) { /* ... */ }
VersionService facade:
namespace App\Services;
use Herrera\Version\{Parser, Comparator, Validator};
class VersionService {
public function parse(string $version): Version {
return Parser::toVersion($version);
}
public function isValid(string $version): bool {
return Validator::isVersion($version);
}
public function incrementPatch(string $version): string {
return Dumper::toString(
Parser::toBuilder($version)->incrementPatch()
);
}
}
deploy.php)./check-updates).if (version >= '1.2.0-beta.3')).Route::middleware(['validate.version' => function ($request, $next) {
$versionService = app(VersionService::class);
if (!$versionService->isValid($request->version)) {
abort(400, 'Invalid version format');
How can I help you explore Laravel packages today?