cekta / di
psr/container implementation for humans
Installs: 378
Dependents: 1
Suggesters: 0
Security: 0
Stars: 82
Watchers: 10
Forks: 7
Open Issues: 6
pkg:composer/cekta/di
Requires
- php: >=8.0
- psr/container: >=2.0
- symfony/filesystem: @stable
Requires (Dev)
- infection/infection: @stable
- phpstan/phpstan: @stable
- phpunit/phpunit: @stable
- squizlabs/php_codesniffer: @stable
Provides
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
- Predictable performance - No dynamic analysis slowing down your application
- ⚡ 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:
namespace App; class Controller { }
bin/build.php:
use Cekta\DI\Compiler; // Configure your dependencies. $compiler = new Compiler( containers: [App\Controller::class], fqcn: 'App\\Runtime\\Container' ); // Generate the container $code = $compiler->compile(); file_put_contents(__DIR__ . '/../runtime/Container.php', $code);
app.php:
use Cekta\DI\Compiler; // Use it in your application $container = new App\Runtime\Container(); $controller = $container->get(App\Controller::class);
📚 Documentation
- Getting Started - Installation and basic setup
- Containers - Defining your application's entry points
- Parameters - Configuring values and instances
- Aliases - Mapping interfaces to implementation
- Lifecycle Management - Scoped, Singleton, and Factory dependencies
- Priority Resolution - Understanding dependency resolution order
- Autoconfiguration - Automatically discovering dependencies
- Service Locator - Using ContainerInterface as a dependency
- Argument Resolution - How arguments become dependency names
- Troubleshooting - Handling circular dependencies
🤝 Community
Join the Telegram chat for discussions in English or Russian.
Cekta/DI - Dependency injection that gets out of your way and lets you focus on building great applications.