Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Version Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • SemVer 2.0.0 Compliance: Aligns with Laravel’s dependency management (Composer) and API versioning best practices, ensuring consistency across PHP-based products.
    • Granular Version Control: Enables programmatic manipulation (e.g., incrementMajor(), clearPreRelease()), critical for CI/CD pipelines, release automation, and feature flag management in Laravel applications.
    • Immutable Design: Version objects reduce side effects, fitting Laravel’s service-layer patterns (e.g., repositories, commands) where purity is desirable.
    • Comparator Utility: Facilitates version-based logic (e.g., enforcing minimum API versions, plugin compatibility checks) without reinventing parsing/comparison logic.
    • Metadata Support: Handles pre-release (alpha, beta) and build metadata (e.g., +commit-hash), useful for canary releases, rollback tracking, or artifact versioning in microservices.
  • Cons:

    • Archived Status: Last release in 2014 raises concerns about:
      • PHP 8.x/Laravel 9+ Compatibility: Potential issues with strict typing, named arguments, or deprecated functions (e.g., create_function).
      • Security: No updates for 10+ years, though SemVer parsing itself is low-risk for CVEs.
    • Laravel-Specific Gaps:
      • No native integration with Laravel’s PackageManifest, Artisan commands, or config() system.
      • Lacks helpers for common Laravel workflows (e.g., versioned migrations, API resource versioning).
    • Overhead for Simple Use Cases: If only parsing/validating versions (e.g., in composer.json), a lightweight regex or Composer\Semver may suffice with less maintenance risk.
    • No Modern Testing: Absence of a test suite or PHPUnit 9+ compatibility may require manual validation of edge cases (e.g., Unicode identifiers, malformed input).

Integration Feasibility

  • Laravel Compatibility:
    • Service Container: Bindable as a singleton or context-bound service:
      $this->app->singleton(Herrera\Version\Parser::class);
      $this->app->bind(Herrera\Version\Comparator::class);
      
    • Facades: Wrap core classes for cleaner syntax (e.g., Version::parse($string)).
    • PHP Version: Requires polyfills for PHP 8.x (e.g., return_type declarations, intval behavior changes).
  • Database/ORM:
    • Useful for versioned records (e.g., schema_versions table, soft-deleted snapshots with versioned metadata).
    • Example: Store version strings in a versions table and validate using Validator::isVersion().
  • APIs:
    • Validate incoming version strings in request payloads (e.g., /updates?version=1.2.3).
    • Enforce version constraints in API gateways (e.g., "reject requests with version < 2.0.0").
  • CI/CD:
    • Automate version bumps in deployment scripts (e.g., incrementPatch() in post-deploy hooks).
    • Example:
      $version = Parser::toBuilder(config('app.version'))
          ->incrementPatch()
          ->getVersion();
      config(['app.version' => Dumper::toString($version)]);
      

Technical Risk

  • High:
    • Deprecation Risk: Archived package may break with PHP 8.x/9.x or Laravel’s evolving dependencies (e.g., Symfony components, strict typing).
    • Testing Overhead: No modern test suite; manual validation required for edge cases (e.g., Unicode in identifiers, malformed input).
    • Maintenance Burden: Future Laravel upgrades (e.g., new PHP features, autoloader changes) may expose incompatibilities.
    • Forking Complexity: Modernizing the package (e.g., adding #[ReturnTypeWillChange], fixing deprecated functions) requires deep codebase knowledge.
  • Mitigation Strategies:
    • Isolation: Use as a private package via composer.json "repositories" to avoid dependency conflicts.
    • Fallback Plan: Implement a minimal wrapper to abstract breaking changes:
      class LaravelVersionService {
          public function parse(string $version): Version {
              try {
                  return Parser::toVersion($version);
              } catch (Exception $e) {
                  // Fallback: Regex parsing or throw custom exception
              }
          }
      }
      
    • Alternative: Replace with php-semver/php-semver or ramsey/uuid if forking fails.

Key Questions

  1. Why not use 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.
  2. How critical is pre-release/build metadata support?
    • If unused, consider a simpler alternative (e.g., explode('.', $version) + regex for basic validation).
  3. Will this replace Laravel’s built-in versioning (e.g., Artisan::version())?
    • No; this is for application-level versioning (e.g., feature flags, release notes, plugin ecosystems). Laravel’s Artisan::version() is for CLI tooling.
  4. What’s the upgrade path if the package breaks?
    • Plan to replace with php-semver/php-semver or a custom solution if forking fails. Document the migration path in UPGRADE.md.
  5. How will this interact with Laravel’s PackageManifest?
    • Use the library to validate versions in composer.json or custom manifest files, but avoid replacing Laravel’s core package resolution.
  6. Performance Impact:
    • For high-frequency comparisons (e.g., API rate limiting by version), benchmark against Composer\Semver to ensure acceptable latency.

Integration Approach

Stack Fit

  • Best Fit:
    • Laravel Applications: Managing multiple versioned entities (e.g., plugins, SDKs, internal microservices, API resources).
    • Release Automation: CI/CD pipelines where version bumps are automated (e.g., incrementPatch() in GitHub Actions).
    • Plugin Ecosystems: Validating plugin compatibility (e.g., "this plugin requires Laravel ^9.0 || ^10.0").
    • Feature Flags: Using pre-release versions (e.g., 1.2.0-beta.1) for canary testing.
  • Avoid:
    • Projects with trivial versioning needs (e.g., single-version CLI tools).
    • Non-PHP stacks (e.g., Node.js, Go; use native tools like npm version or go-mod-version).
    • Teams requiring active maintenance or non-SemVer schemas (e.g., date-based versions like 2023.10.1).

Migration Path

  1. Assessment Phase:
    • Audit existing versioning logic:
      • Custom Version classes or regex parsing.
      • Hardcoded version strings in config/files.
      • Manual version comparisons in business logic.
    • Identify pain points (e.g., inconsistent comparisons, manual bump errors, lack of pre-release support).
  2. Pilot Integration:
    • Replace a single use case (e.g., release pipeline or API version validation).
    • Example: Replace manual version parsing in a 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'))) { /* ... */ }
      
  3. Full Adoption:
    • Phase 1: Add as a dev dependency and create a 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()
              );
          }
      }
      
    • Phase 2: Replace all version-related logic:
      • Release scripts (e.g., deploy.php).
      • API endpoints (e.g., /check-updates).
      • Feature flag logic (e.g., if (version >= '1.2.0-beta.3')).
    • Phase 3: Add validation middleware for versioned payloads:
      Route::middleware(['validate.version' => function ($request, $next) {
          $versionService = app(VersionService::class);
          if (!$versionService->isValid($request->version)) {
              abort(400, 'Invalid version format');
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky