cekta / di
psr/container implementation for humans
v3.0.1
2026-08-15 22:10 UTC
Requires
- php: >=8.2
- psr/container: >=2.0
Requires (Dev)
- infection/infection: @stable
- phpstan/phpstan: @stable
- phpunit/phpunit: @stable
- squizlabs/php_codesniffer: @stable
Suggests
None
Provides
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-19 14:49:17 UTC
README
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);
📚 Documentation
🤝 Community
Join the Telegram chat for discussions in English or Russian.