jardissupport/factory

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

Maintainers

Package info

github.com/jardisSupport/factory

pkg:composer/jardissupport/factory

Statistics

Installs: 118

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-03-31 08:32 UTC

This package is auto-updated.

Last update: 2026-03-31 08:32:59 UTC


README

Build Status License: PolyForm Shield PHP Version PHPStan Level PSR-12 PSR-11

Part of the Jardis Business Platform — Enterprise-grade PHP components for Domain-Driven Design

PSR-11 Container with pre-registered instances and reflection fallback. Three source files, one dependency (psr/container), zero configuration overhead.

Features

  • PSR-11 ContainerInterface — standard get() and has() contract
  • Pre-registered Instances — pass objects at construction, retrieved by key
  • Backend Container Delegation — delegates to Symfony, Laravel, PHP-DI, or any PSR-11 container
  • Reflection Fallback — classes without required constructor params are instantiated automatically
  • Resolution Order — Instances → Backend → Reflection, each step optional
  • Immutable — all configuration via constructor, readonly after creation

Installation

composer require jardissupport/factory

Quick Start

use JardisSupport\Factory\Factory;

// Minimal — uses reflection for instantiation
$factory = new Factory();
$instance = $factory->get(MyService::class);

// With pre-registered instances
$factory = new Factory(instances: [
    LoggerInterface::class => $logger,
    CacheInterface::class => $cache,
]);

$factory->get(LoggerInterface::class);  // → $logger
$factory->get(SomeSimpleClass::class);  // → new instance via reflection

// With backend container
$factory = new Factory(container: $symfonyContainer, instances: [
    'override.service' => $myOverride,
]);

// Instances win over backend; backend wins over reflection

Resolution Order

get($id)
  ├── 1. Pre-registered instances (exact key match)
  ├── 2. Backend container ($container->has($id) ? $container->get($id))
  └── 3. Reflection (class_exists($id) ? new $id())

If none matches → NotFoundException. If class exists but has required constructor params → ContainerException.

License

This package is licensed under the PolyForm Shield License 1.0.0. Free for all use except building competing frameworks or developer tooling.

Jardis · Documentation · Headgent