Skip to content

Repository files navigation

Jardis Factory

Build StatusLicense: MITPHP VersionPHPStan LevelPSR-12PSR-11

Part of Jardis — 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.

Lightweight PSR-11 container for PHP 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

useJardisSupport\Factory\Factory;
// Minimal — uses reflection for instantiation$factory = newFactory();
$instance = $factory->get(MyService::class);
// With pre-registered instances$factory = newFactory(instances: [
LoggerInterface::class => $logger,
CacheInterface::class => $cache,
]);
$factory->get(LoggerInterface::class); // → $logger$factory->get(SomeSimpleClass::class); // → new instance via reflection// With backend container$factory = newFactory(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.

Documentation

Full documentation, guides, and API reference:

docs.jardis.io/en/support/factory


License

This package is licensed under the MIT License.


Jardis · Documentation · Headgent

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: https://docs.jardis.io/en/skills

About

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

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages