Search by

cekta / di

smpl

psr/container implementation for humans

Package info

github.com/cekta/di

pkg:composer/cekta/di

Statistics

Installs: 795

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

<?php
// src/Example.php
class Example {
    public function __construct(private \PDO $db) {}
}

1. Configure — define your dependencies

<?php
// src/Project.php
class Project extends \Cekta\DI\AbstractProject
{
    public function __construct(public readonly array $env = getenv())
    {
        parent::__construct(
            filename: __DIR__ . '/../Container.php',
            fqcn: 'App\Container',
            params: [
                \PDO::class . '$dsn' => $env['DB_DSN'] ?? 'sqlite:' . __DIR__ . '/../mydb.sqlite',
            ],
        );
    }

    public function definition(): array
    {
        return ['entries' => [\App\Example::class]];
    }
}

2. Compile — generate the container

<?php
$project = new \App\Project();
file_put_contents(
    $project->filename,
    (new \Cekta\DI\ContainerGenerator())->compile($project)
);

3. Use — get your dependencies

<?php
$project = new \App\Project();
$container = (new \Cekta\DI\ContainerFactory())->create($project);
$example = $container->get(\App\Example::class);

full documentation →

📚 Documentation

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

🤝 Community

Join the Telegram chat for discussions in English or Russian.