-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Muhammet Şafak edited this page May 29, 2026
·
2 revisions
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/containeruse 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- New to the package? Read Installation, then Quick Start.
- Letting the container build your classes? See Autowiring.
- Registering values, factories or interfaces? Read Binding & Factories.
-
Wondering how
get/has/ caching behave? Read Resolution & Caching. - Handling failures? Read Exceptions.
- Hitting a wall? Read Limitations before filing an issue.
-
Upgrading from an early
dev-mainsnapshot? Read the Migration Guide. - Looking for a specific method? The full API Reference lists every member.
| 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.
- License: MIT
- Minimum PHP: 8.1 (also tested on 8.2, 8.3, 8.4)
-
Runtime dependencies:
psr/container^2.0 -
Provides:
psr/container-implementation2.0 -
Packagist:
initphp/container - Source: github.com/InitPHP/Container
- Issues: github.com/InitPHP/Container/issues
- Discussions: github.com/orgs/InitPHP/discussions
-
Security:
SECURITY.md
If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.
initphp/container · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core Usage
Reference
Practical Guides
Migration & Help