cakephp/container

A fast and intuitive dependency injection container.

Maintainers

Package info

github.com/cakephp/container

Homepage

Issues

Forum

pkg:composer/cakephp/container

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

5.x-dev 2026-07-21 20:51 UTC

This package is auto-updated.

Last update: 2026-07-22 03:52:41 UTC


README

Total Downloads License

CakePHP Container Library

The Container library provides a PSR-11 compatible dependency injection container for defining application services and resolving their dependencies.

Usage

Services can be defined with concrete classes, shared instances, factory functions, or interface mappings:

use App\Service\AuditLogService;
use App\Service\AuditLogServiceInterface;
use App\Service\ApiClient;
use App\Service\BillingService;
use Cake\Container\Container;

$container = new Container();

// Add a concrete class.
$container->add(BillingService::class);

// Add a singleton service.
$container->addShared('apiClient', fn () => new ApiClient('https://example.com'));

// Add an implementation for an interface.
$container->add(AuditLogServiceInterface::class, AuditLogService::class);

$billing = $container->get(BillingService::class);

Definitions can also have arguments, tags, and service providers attached when your application needs more control over how objects are built.

Documentation

Please make sure you check the official documentation