wikimedia/object-factory
Wikimedia ObjectFactory builds PHP objects from declarative specifications, mapping class names, constructor arguments, and factory callables to instances. Lightweight, dependency-free, and used by Wikibase and other Wikimedia projects.
class + args + calls in configuration) rather than shipping code changes to core. This library is the primitive that makes that pattern cheap instead of bespoke.switch statements), building test doubles from specs, and deserializing behavior from JSON/YAML/PHP config.Consider it when:
calls) — that's the distinguishing feature versus most containers.Look elsewhere when:
To executives: This is a small, battle-tested utility extracted from MediaWiki — the software behind Wikipedia — that lets us assemble features from configuration rather than code. It lowers the cost of adding extension points and lets configuration owners change wiring without a deploy. Two risks to flag: the GPL-2.0 license needs legal sign-off, and external adoption is negligible (5 stars, 0 dependents), so we'd be owning it ourselves. The mitigating factor is that it's a few hundred lines with a single entry point — ownership is cheap.
To engineering: Single-purpose, no runtime dependencies, one main API (ObjectFactory::getObjectFromSpec) supporting class names, factory callables, positional/named args, and post-construction method calls. The trade-off versus a DI container is deliberate: less magic, no autowiring, no ecosystem — but also no framework coupling and nothing to learn. Recommendation: adopt only if declarative, spec-based object construction is an actual product requirement (third-party extension registration, config-driven behavior). If you just want dependency injection, use what you already have.
How can I help you explore Laravel packages today?