PHPackages                             jardissupport/factory - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. jardissupport/factory

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

jardissupport/factory
=====================

PSR-11 Container with pre-registered instances and reflection fallback

v1.0.0(1mo ago)0601proprietaryPHPPHP &gt;=8.2CI failing

Since Mar 29Pushed 2mo agoCompare

[ Source](https://github.com/jardisSupport/factory)[ Packagist](https://packagist.org/packages/jardissupport/factory)[ Docs](https://github.com/jardisSupport/factory)[ RSS](/packages/jardissupport-factory/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (6)Used By (1)

Jardis Factory
==============

[](#jardis-factory)

[![Build Status](https://github.com/jardisSupport/factory/actions/workflows/ci.yml/badge.svg)](https://github.com/jardisSupport/factory/actions/workflows/ci.yml/badge.svg)[![License: PolyForm Shield](https://camo.githubusercontent.com/d8fb46c82be4c5312bf3e372ac734dfdf6a8b328e9c2b2856af671adbb0600a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d506f6c79466f726d253230536869656c642d626c75652e737667)](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)[![PSR-11](https://camo.githubusercontent.com/6c0874402e8c4ffbef9afa9d041ec10c657e5234692fca736c9ce564e0fc4957/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6e7461696e65722d5053522d2d31312d627269676874677265656e2e737667)](https://www.php-fig.org/psr/psr-11/)[![Coverage](https://camo.githubusercontent.com/c202fb1d1198c964de8c099eae729a6c2f120c7a4d18848ee63d0a17a25d9124/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d3130302e30302532352d627269676874677265656e2e737667)](https://github.com/jardisSupport/factory)

> Part of the **[Jardis Business Platform](https://jardis.io)** — Enterprise-grade PHP components for Domain-Driven Design

Smart class instantiation with version resolution, PSR-11 container integration, and singleton registry. Resolves the right implementation at runtime — versioned, shared, or freshly constructed. Single `Factory` class, zero configuration overhead.

---

Features
--------

[](#features)

- **Version Resolution** — delegates class resolution to any `ClassVersionInterface` before instantiation
- **PSR-11 Container Integration** — asks the container first; falls back to reflection-based construction when the container does not know the class
- **Singleton Registry** — `registerShared()` caches one instance per class + version combination
- **Parameter Forwarding** — pass constructor arguments directly to `get()` via variadic parameters
- **Resolution Chain** — ClassVersion → Container → Reflection, each step optional
- **Single Class** — the entire package is one `Factory.php` file with no hidden bloat

---

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

[](#installation)

```
composer require jardissupport/factory
```

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

[](#quick-start)

```
use JardisSupport\Factory\Factory;

// No dependencies — uses reflection for instantiation
$factory = new Factory();

$instance = $factory->get(MyService::class);

// With constructor parameters
$instance = $factory->get(MyService::class, null, $param1, $param2);

// Register as shared — subsequent calls return the same instance
$factory->registerShared(MyService::class);
$a = $factory->get(MyService::class);
$b = $factory->get(MyService::class);
// $a === $b
```

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

[](#advanced-usage)

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

// Build a ClassVersion resolver
$config = new ClassVersionConfig(
    version: ['V2' => ['v2'], 'V1' => ['v1']],
    fallbacks: ['V2' => ['V1']],
);
$classVersion = new ClassVersion($config, new LoadClassFromSubDirectory($config));

// Factory with PSR-11 container + version resolver
$factory = new Factory($container, $classVersion);

// Resolve App\Repository\V2\UserRepository (or fall back to V1)
// Container is consulted first; reflection is used as the final fallback
$repo = $factory->get(App\Repository\UserRepository::class, 'v2');

// Register multiple classes as shared singletons
$factory->registerShared([
    App\Repository\UserRepository::class,
    App\Service\DataService::class,
]);

// First call constructs; subsequent calls return the cached instance
$repo1 = $factory->get(App\Repository\UserRepository::class, 'v2');
$repo2 = $factory->get(App\Repository\UserRepository::class, 'v2');
// $repo1 === $repo2

// Different version → separate cached instance
$repo3 = $factory->get(App\Repository\UserRepository::class, 'v1');
// $repo1 !== $repo3
```

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

[](#documentation)

Full documentation, guides, and API reference:

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

License
-------

[](#license)

This package is licensed under the [PolyForm Shield License 1.0.0](LICENSE.md). Free for all use except building competing frameworks or developer tooling.

---

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

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance89

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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 ~31 days

Total

2

Last Release

51d 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 (1 commits)")

---

Tags

containerPSR-11factoryHeadgentjardis

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[chubbyphp/chubbyphp-container

A simple PSR-11 container implementation.

1978.4k14](/packages/chubbyphp-chubbyphp-container)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)[selective/container

A simple PSR-11 container implementation with autowiring.

1220.4k4](/packages/selective-container)[devanych/di-container

Simple implementation of a PSR-11 dependency injection container

124.2k3](/packages/devanych-di-container)

PHPackages © 2026

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