jardissupport/factory

Flexible class instantiation with optional versioning and dependency injection.

Installs: 79

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/jardissupport/factory

1.0.0 2026-02-25 17:31 UTC

README

Build Status License: PolyForm NC PHP Version PHPStan Level PSR-4 PSR-11 PSR-12 Coverage

Part of the Jardis Ecosystem — A modular DDD framework for PHP

A flexible class instantiation factory for PHP applications. Unlike traditional factory implementations, Jardis Factory supports optional class versioning and PSR-11 container integration — enabling dynamic class resolution with fallback to reflection-based instantiation.

Features

  • PSR-11 Container Integration — Automatically resolves dependencies from any PSR-11 compatible container
  • Optional Class Versioning — Supports versioned class resolution through ClassVersionInterface
  • Shared Class Registry — Register stateless services as shared for automatic instance caching per version
  • Flexible Parameter Passing — Supports both variadic and array-based parameter passing
  • Reflection Fallback — Creates instances via reflection when no container is available
  • Zero Configuration — Works out of the box without any dependencies

Installation

composer require jardissupport/factory

Quick Start

use JardisSupport\Factory\Factory;

// Simple usage without dependencies
$factory = new Factory();
$instance = $factory->get(MyClass::class);

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

// With PSR-11 container
$factory = new Factory($container);
$instance = $factory->get(MyService::class);

// With class versioning
$factory = new Factory($container, $classVersion);
$instance = $factory->get(MyClass::class, 'v2.0');

// Register stateless services as shared (singleton per version)
$factory->registerShared([
    Repository::class,
    DataService::class,
    DbQuery::class,
]);

// Subsequent calls return the same instance
$repo1 = $factory->get(Repository::class, 'v1');
$repo2 = $factory->get(Repository::class, 'v1');
// $repo1 === $repo2

Documentation

Full documentation, examples and API reference:

jardis.io/docs/support/factory

Jardis Ecosystem

This package is part of the Jardis Ecosystem — a collection of modular, high-quality PHP packages designed for Domain-Driven Design.

Category Packages
Core Kernel, Entity, Workflow
Support DotEnv, Cache, Logger, Messaging, DbConnection, DbQuery, DbSchema, Validation, Factory, ClassVersion
Generic Auth
Tools Builder, Migration, Faker

Explore all packages

License

This package is licensed under the PolyForm Noncommercial License 1.0.0.

For commercial use, see COMMERCIAL.md.

Jardis Ecosystem by Headgent Development