🦖
[■] codesaur/container 1=[↕]
codesaur/container · v3.2.0

Container

Lightweight, fast, PSR-11 compliant dependency injection container

Packagist version Downloads PHP version License Aikido Intel 95/100 PSR-11
1:1 ══ composer require codesaur/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

ClassPurpose
ContainerPSR-11 container - set(), get(), has(), aliases, bindings
ContainerExceptionError while building a service
NotFoundExceptionService 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
Aikido score 95/100
Checked: 2026-09-10
Links