Wirebox
Lightweight PHP 8.4 DI Container with Autowiring, Attributes & Compiled Container.
Get Started Русский 中文 View on GitHub
What is Wirebox?
Wirebox is a modern, zero-configuration dependency injection container for PHP 8.4+. It leverages the latest PHP features — native attributes, lazy objects, and reflection — to provide a powerful yet simple DI experience.
Key Highlights
- Zero configuration — Point at a directory, all concrete classes are auto-registered
- PSR-11 compatible — Standard
ContainerInterfaceimplementation - PHP 8.4 Attributes — Configure services declaratively with
#[Singleton],#[Inject],#[Lazy], and more - Autowiring — Constructor dependencies resolved automatically via type hints
- Compiled container — Generate a PHP class with zero reflection at runtime for production
- Lazy proxies — Deferred instantiation via PHP 8.4 native lazy objects
- Built-in dotenv — No external dependencies for environment variable support
- Autoconfiguration — Symfony-style auto-tagging by interface or attribute
Quick Example
use AsceticSoft\Wirebox\ContainerBuilder;
$builder = new ContainerBuilder(projectDir: __DIR__);
$builder->scan(__DIR__ . '/src');
$container = $builder->build();
$service = $container->get(App\UserService::class);
That’s it. Three lines to get a fully working DI container with autowiring. No XML, no YAML, no boilerplate.
Why Wirebox?
| Feature | Wirebox | Other containers |
|---|---|---|
| PHP 8.4 native lazy objects | Yes | Proxy generation |
| Zero-config directory scanning | Yes | Manual registration |
Built-in .env support |
Yes | External packages |
| Compiled container | Yes | Some |
| Autoconfiguration | Yes | Some |
| Minimal dependencies | psr/container only |
Often many |
| PHPStan Level 9 | Yes | Varies |
Requirements
- PHP >= 8.4
- psr/container ^2.0
Installation
composer require ascetic-soft/wirebox
Documentation
Getting Started
Installation, first container, and basic usage in 5 minutes.
Configuration
Directory scanning, bindings, factories, and fluent API.
Attributes
All PHP attributes: Singleton, Transient, Inject, Param, Tag, and more.
Environment Variables
Built-in dotenv, 3-level priority, type casting.
Compiled Container
Zero-reflection production container generation.
Advanced
Autoconfiguration, tagged services, lazy proxies, circular dependencies.
API Reference
Complete reference for all public classes and methods.