cekta/di

psr/container implementation for humans

Maintainers

Package info

github.com/cekta/di

pkg:composer/cekta/di

Transparency log

Statistics

Installs: 768

Dependents: 1

Suggesters: 0

Stars: 80

Open Issues: 0

v3.0.1 2026-08-15 22:10 UTC

README

Telegram chat Mutation testing badge Latest Stable Version License

A modern, high-performance PSR-11 Container implementation designed for developers who value simplicity and performance.

✨ Features

  • 🚀 Zero Runtime Overhead - All dependencies are resolved during compilation, not at runtime
  • No runtime reflection - All dependency resolution happens during compilation
  • OPcache Ready - Generated code works perfectly with PHP's opcode cache
  • 🔧 Flexible Configuration - Mix autowiring with explicit configuration
  • 📦 Full PSR-11 Compliance - Implements the standard Container Interface
  • 🔄 Modern PHP Support - Works with Union Types, Intersection Types, DNF Types, and variadic arguments
  • 🧩 Interface & Abstract Class Support - Full dependency injection for abstractions
  • 🎯 High Code Quality - Rigorously tested with mutation testing
  • Easy debugging - Generated container is plain PHP code you can read and understand

📦 Installation

composer require cekta/di

🚀 Quick Start

src/Controller.php

<?php

namespace App;

class Controller
{
    public function __construct(private \PDO $service) 
    {
    }
}

bin/build.php

<?php

require __DIR__ . './../vendor/autoload.php';

// Configure your dependencies.
$builder = new \Cekta\DI\ContainerBuilder(
    containers: [\App\Controller::class],
    params: [
        \PDO::class . '$dsn' => 'sqlite:database.sqlite',
    ],
    fqcn: 'App\\Runtime\\Container'
);

// Generate the container
$code = $builder->compile();
file_put_contents(__DIR__ . '/../runtime/Container.php', $code);

CLI: generate container

php bin/build.php

now we can use generated /runtime/Container.php in our project

app.php

<?php

require __DIR__ . './vendor/autoload.php';

// Use it in your application
$container = new \App\Runtime\Container([
    \PDO::class . '$dsn' => 'sqlite:database.sqlite', // can be changed, but required!!!
]);
$controller = $container->get(\App\Controller::class);

📚 Documentation

https://cekta.github.io/di/

🤝 Community

Join the Telegram chat for discussions in English or Russian.