[■]
codesaur/container
1=[↕]
1:1 ══ composer require codesaur/container
codesaur/container · v3.2.0
Container
Lightweight, fast, PSR-11 compliant dependency injection container
[■]
Container
A DI container implementing PSR-11 ContainerInterface with lazy loading, auto-wiring, interface binding and service aliases. It resolves dependencies automatically through Reflection. A core component of the codesaur ecosystem that can be used independently in any PHP project.
Features
- PSR-11 ContainerInterface implementation
- Lazy Loading - services are created only when needed
- Auto-wiring - automatic constructor dependency resolution
- Interface Binding - bind interfaces to implementations
- Service Aliases - access one service by multiple names
- Closure / callable factory support
- Framework-agnostic with no external dependencies
Core classes
| Class | Purpose |
|---|---|
Container | PSR-11 container - set(), get(), has(), aliases, bindings |
ContainerException | Error while building a service |
NotFoundException | Service not found error (PSR-11) |
Quick example
use codesaur\Container\Container;
// Контейнер үүсгэх / Create container
$container = new Container();
// Класс бүртгэх / Register class
$container->set(MyService::class);
// Параметртэй класс бүртгэх / Register class with parameters
$container->set(Printer::class, ['Hello, World!']);
// Сервис авах / Get service
$service = $container->get(MyService::class);
$printer = $container->get(Printer::class);
// Сервис байгаа эсэхийг шалгах / Check if service exists
if ($container->has(MyService::class)) {
$printer->print(); // Output: Hello, World!
}
Running tests
composer test
[■]
Info
Install
composer require codesaur/container
Requirements
- PHP 8.2.1+
- Composer
Documentation