PHPackages                             jardissupport/classversion - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jardissupport/classversion

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jardissupport/classversion
==========================

Runtime class versioning via namespace injection with configurable fallback chains and proxy caching

v1.0.3(3w ago)03911MITPHPPHP &gt;=8.2CI passing

Since Jun 2Pushed 3w agoCompare

[ Source](https://github.com/jardisSupport/classversion)[ Packagist](https://packagist.org/packages/jardissupport/classversion)[ Docs](https://jardis.io)[ RSS](/packages/jardissupport-classversion/feed)WikiDiscussions main Synced yesterday

READMEChangelog (4)Dependencies (8)Versions (8)Used By (1)

Jardis ClassVersion
===================

[](#jardis-classversion)

[![Build Status](https://github.com/jardisSupport/classversion/actions/workflows/ci.yml/badge.svg)](https://github.com/jardisSupport/classversion/actions/workflows/ci.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/a68b290dcc313d698dc138a1111aa83eee2f143605449d7e8b5416ea6f88558f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e322d3737374242342e737667)](https://www.php.net/)[![PHPStan Level](https://camo.githubusercontent.com/c51bda247654363d3e30bc352674dd761a9557803a14af0226eb411d6dc0006b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e737667)](phpstan.neon)[![PSR-12](https://camo.githubusercontent.com/34b10db0caa29bacd49bda5c437a8de95385f036f3230b31fa605326e18da22c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64652532305374796c652d5053522d2d31322d626c75652e737667)](phpcs.xml)[![Coverage](https://camo.githubusercontent.com/18f6a2df42ae1afe8a625856c82e58467ea6af9260d0dfafd9c90ed2cab3d400/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d39362e36392532352d627269676874677265656e2e737667)](https://github.com/jardisSupport/classversion)

> Part of **[Jardis](https://jardis.io)** — the Domain-Driven Design platform for PHP. You model your domain; Jardis generates the production-ready hexagonal code (DTOs, Command/Query handlers, repositories, persistence). This package is part of the open-source foundation that generated code runs on.

Runtime class versioning for PHP via namespace injection — the mechanism that lets Jardis-generated hexagonal code grow through versions without breaking call sites. Load different implementations of the same class by version label, configure fallback chains so a missing version silently degrades to the previous one, register proxy instances for hot-swapping at test or runtime, and deploy new logic without touching existing code.

---

Features
--------

[](#features)

- **SubDirectory Resolution** — injects a version label into the namespace to locate versioned class implementations
- **Extensions Resolution** — inserts a fixed `Extensions/` segment at a configurable namespace depth to pick up baseline and versioned overrides side by side
- **Proxy Registry** — pre-register object instances via `LoadClassFromProxy` that are returned directly, bypassing class loading
- **Resolution Cache** — optional `ClassResolutionCache` memoizes hits **and** misses, eliminating repeated `class_exists()` / `stat()` syscalls on hot paths
- **Fallback Chains** — define ordered fallback sequences in `ClassVersionConfig` so resolution degrades gracefully across versions
- **Version Groups + Aliases** — map multiple labels to one canonical version key
- **Tracing Decorator** — wrap any resolver in `TracingClassVersion` to record every resolution for debugging
- **Zero-coupling** — works with any PSR-4 autoloader, no framework dependency required

---

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

[](#installation)

```
composer require jardissupport/classversion
```

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

[](#quick-start)

```
use JardisSupport\ClassVersion\Data\ClassVersionConfig;
use JardisSupport\ClassVersion\Reader\LoadClassFromSubDirectory;
use JardisSupport\ClassVersion\ClassVersion;

// Map version labels to canonical subdirectory names
$config = new ClassVersionConfig(
    version: ['V2' => ['v2', '2.0'], 'V1' => ['v1', '1.0']],
);

$resolver = new ClassVersion(
    $config,
    new LoadClassFromSubDirectory($config),
);

// Resolves App\Service\V2\Calculator (namespace injection)
$className = $resolver(App\Service\Calculator::class, 'v2');

$instance = new $className();
```

Advanced Usage
--------------

[](#advanced-usage)

```
use JardisSupport\ClassVersion\Data\ClassVersionConfig;
use JardisSupport\ClassVersion\Reader\LoadClassFromSubDirectory;
use JardisSupport\ClassVersion\Reader\LoadClassFromProxy;
use JardisSupport\ClassVersion\ClassVersion;
use JardisSupport\ClassVersion\Support\ClassResolutionCache;
use JardisSupport\ClassVersion\Support\TracingClassVersion;

// Fallback chain: if V2 namespace is missing, try V1 before the base class
$config = new ClassVersionConfig(
    version: ['V2' => ['v2', '2.0'], 'V1' => ['v1', '1.0']],
    fallbacks: ['V2' => ['V1']],
);

// Proxy registry: return a pre-built instance for a specific class + version
$proxy = new LoadClassFromProxy($config);
$proxy->addProxy(App\Service\Calculator::class, new MyTestCalculator(), 'v2');

// Optional: resolution cache memoizes hits and misses — same (class, version)
// key never hits the autoloader twice.
$resolver = new ClassVersion(
    $config,
    new LoadClassFromSubDirectory($config),
    $proxy,
    cache: new ClassResolutionCache(),
);

// Wrap with tracing decorator to record all resolutions
$tracing = new TracingClassVersion($resolver);

// Returns the pre-registered proxy instance directly
$result = $tracing(App\Service\Calculator::class, 'v2');

// Resolves App\Service\V2\Formatter — falls back to V1 if the V2 namespace is absent
$className = $tracing(App\Service\Formatter::class, 'v2');
$instance = new $className();

// Inspect the resolution log
foreach ($tracing->getTrace() as $entry) {
    echo $entry['requested'] . ' [' . ($entry['version'] ?? 'default') . ']'
        . ' → ' . $entry['type'] . PHP_EOL;
}

$tracing->clearTrace();
```

Extensions Resolution
---------------------

[](#extensions-resolution)

`LoadClassFromExtensions` is a second, parametrised resolver for projects that keep developer-owned overrides in a dedicated directory. Configure two pieces: `depth` (how many namespace segments from the left make up the "root") and `segmentNames` (one or more directory names to probe in order, e.g. `['Extensions']`, `['', 'Platform']`, `['Overrides', 'Customizations']`). The empty string `''` is a legal segment value meaning "no subdir inserted" — use it to keep the override layer at the aggregate root.

```
use JardisSupport\ClassVersion\Reader\LoadClassFromExtensions;

$config = new ClassVersionConfig(
    version: ['v2' => ['v2'], 'v1' => ['v1']],
);

$resolver = new ClassVersion(
    $config,
    new LoadClassFromExtensions(depth: 3, segmentNames: ['Extensions'], versionConfig: $config),
);

// Lookup order for App\Order\Order\Command\Handler\CreateOrder:
//   1. App\Order\Order\Extensions\{v2-chain}\Command\Handler\CreateOrder  (if version set)
//   2. App\Order\Order\Extensions\Command\Handler\CreateOrder             (baseline override)
//   3. App\Order\Order\Command\Handler\CreateOrder                        (generator base)
$className = $resolver(App\Order\Order\Command\Handler\CreateOrder::class, 'v2');
```

### Multi-segment lookup (versions-first across layers)

[](#multi-segment-lookup-versions-first-across-layers)

`segmentNames` accepts more than one segment to probe parallel override layers in priority order. The reader walks the **version chain first, all segments per version**, before falling back to versionless baselines:

```
$resolver = new LoadClassFromExtensions(
    depth: 3,
    segmentNames: ['', 'Platform'],
    versionConfig: $config,
);

// Lookup order for App\Order\Order\Command\Handler\CreateOrder, version 'v2':
//   1. App\Order\Order\v2\Command\Handler\CreateOrder           (dev override v2)
//   2. App\Order\Order\Platform\v2\Command\Handler\CreateOrder  (platform v2)
//   3. App\Order\Order\Command\Handler\CreateOrder              (dev baseline)
//   4. App\Order\Order\Platform\Command\Handler\CreateOrder     (platform baseline)
//   5. App\Order\Order\Command\Handler\CreateOrder              (generator-base fallback)
```

A versioned hit in any segment wins over a versionless hit in any segment — that is the "versions-first" semantics. Including `''` in `segmentNames`makes the version chain probe the aggregate root directly without an intermediate segment.

Classes with fewer than `depth + 1` namespace segments skip the override lookup and resolve against the generator base directly. No configuration defaults — the caller decides the layout convention explicitly.

Documentation
-------------

[](#documentation)

Full documentation, guides, and API reference:

**[docs.jardis.io/en/support/classversion](https://docs.jardis.io/en/support/classversion)**

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE.md).

---

**[Jardis](https://jardis.io)** · [Documentation](https://docs.jardis.io) · [Headgent](https://headgent.com)

AI-Assisted Development
-----------------------

[](#ai-assisted-development)

This package ships with a skill for Claude Code, Cursor, Continue, and Aider. Install it in your consuming project:

```
composer require --dev jardis/dev-skills
```

More details:

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance96

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

4

Last Release

21d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e07a1b668e9e01ee6d1b85de7b3be1c2513f68aae9494b2011d1592104d5daa0?d=identicon)[jardis](/maintainers/jardis)

---

Top Contributors

[![Headgent](https://avatars.githubusercontent.com/u/245725954?v=4)](https://github.com/Headgent "Headgent (7 commits)")

---

Tags

class-loadingclass-versioningdomain-driven-designjardisphpversioningphploaderversioningDomain Driven Designhexagonal-architectureHeadgentjardisjardisSupportclassversionclass-versioningclass-loading

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jardissupport-classversion/health.svg)

```
[![Health](https://phpackages.com/badges/jardissupport-classversion/health.svg)](https://phpackages.com/packages/jardissupport-classversion)
```

###  Alternatives

[dykyi-roman/awesome-claude-code

Claude Code extension for PHP: audits (architecture, DDD, security, performance, PSR, design patterns, Docker, CI/CD, tests, docs), 3-level code review, automated bug fix, generators (DDD, CQRS, GoF patterns, PSR, tests, documentation, Docker, CI/CD), code explanation, refactoring. 26 commands, 62 agents, 259 skills.

851.2k](/packages/dykyi-roman-awesome-claude-code)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
