Skip to content
Muhammet Şafak edited this page May 29, 2026 · 2 revisions

InitPHP Container — Wiki

Welcome to the official documentation for initphp/container — a small, PSR-11 dependency injection container that resolves entries on demand and autowires class dependencies through reflection.

The package ships two public types:

Type Purpose
Container The concrete container; register entries and retrieve them.
Psr\Container\ContainerInterface The PSR-11 contract Container implements; depend on this in your services.

Container implements Psr\Container\ContainerInterface, so it drops into any code that consumes the standard get() / has() contract.

composer require initphp/container
use InitPHP\Container\Container;

class Mailer {}

class UserService
{
    public function __construct(public Mailer $mailer) {}
}

$container = new Container();

// No registration needed — the container reads UserService's constructor,
// builds the Mailer dependency and injects it.
$service = $container->get(UserService::class);

$service instanceof UserService;        // true
$service->mailer instanceof Mailer;     // true

Start here

At a glance — feature matrix

Capability Supported
PSR-11 get() / has()
Constructor autowiring (reflection)
Recursive dependency resolution
Lazy Closure factories
Binding an interface/identifier to a class
Storing arbitrary values (scalars, arrays, objects)
Shared (singleton) instances ✅ (always)
Circular dependency detection
Optional-dependency fallback (default / null)
Union / intersection type autowiring ❌ (falls back to default / null)
Transient (per-call) instances
Contextual / tagged bindings
Method / property / attribute injection

See Limitations for the rationale behind the unsupported rows.

Package metadata

If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.

Clone this wiki locally