lekoala / kaly-di
Requires
- php: ^8.3
- psr/container: ^1.1.2|^2.0.2
Requires (Dev)
- carthage-software/mago: 1.10.0
- composer/ca-bundle: ^1.5
- phpstan/phpstan: ^2
- phpunit/phpunit: ^11
- rector/rector: ^2
- squizlabs/php_codesniffer: ^3.10
- dev-master
- dev-cleanup-unused-import-injector-2845890558149985591
- dev-optimize-array-merge-15273401142251151041
- dev-performance/cache-callbacks-reflection-12422144988372225407
- dev-refactor-simplify-array-key-exists-check-1827021334068523485
- dev-performance-container-has-caching-2728612423129514249
- dev-code-health/bindAll-return-type-4221023041942030740
- dev-testing-improvement-create-container-734844172658210447
- dev-performance-reflection-cache-7452373603095367863
- dev-cleanup-injector-variables-4575157287007882305
- dev-fix/debug-type-match-15056844121155772373
This package is auto-updated.
Last update: 2026-03-27 17:00:45 UTC
README
Minimalist and Modern Dependency Injection Container for PHP 8.3+
Kaly DI is a lightweight, flexible, and PSR-11 compliant dependency injection (DI) container designed for modern PHP applications. It emphasizes simplicity, performance, and clear code without reliance on attributes or "magic."
Key Features
- PSR-11 Compliance: Seamlessly interoperable with PHP standards.
- No Attributes, No Magic: Keep your code clean and decoupled from the container.
- Strongly Typed Definitions: Define dependencies in PHP for full IDE support (autocompletion, refactoring).
- Advanced Auto-wiring: Automatic dependency resolution, fine-tunable with resolvers.
- Performance Focused: Minimal overhead, designed to be extremely fast.
- Developer Friendly: Comprehensive error reporting and development-only assertions.
Installation
composer require lekoala/kaly-di
Quick Start
use Kaly\Di\Container; use Kaly\Di\Definitions; // 1. Define dependencies $definitions = Definitions::create() ->set(\PDO::class, new \PDO('sqlite::memory:')); // 2. Create the container $container = new Container($definitions); // 3. Get auto-wired instances $myObject = $container->get(MyClass::class);
Documentation
Detailed guides are available in the docs/ directory:
- Definitions: Setting services, binding interfaces, parameters, and callbacks.
- Resolvers: Managing complex auto-wiring and type conflicts.
- Injector: Creating fresh instances and invoking callables.
- Architecture: Internal design, design decisions, and exceptions.
A Note on Assertions
Kaly DI uses PHP assert() for input validation (e.g., checking class existence, definition lock, type compatibility). This is by design: these checks run automatically in development (zend.assertions = 1) but are disabled in production (zend.assertions = -1) for zero overhead.
Ensure your test suite covers your DI configuration to catch mistakes before deployment.
Examples and Testing
Check the unit tests for comprehensive usage examples covering all features.