duyler / di
Dependency injection container
dev-main
2024-11-11 06:12 UTC
Requires
- php: >=8.3
- psr/container: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.30
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-12-11 06:19:09 UTC
README
The dependency injection container
This package makes it possible to quickly connect the DI-container to your project.
The container can be used both in automatic mode, using type hints in class constructors, and accept fine-tuning using providers.
Example automatically make instance
use Duyler\DI\Container; use YourClass; $container = new Container; $yourClassObject = $container->get(YouClass::class);
Make instance with provider
class YourClass { private MyClassInterface $myImplements; public function __construct(MyClassInterface $myImplements) { $this->myImplements = $myImplements; } }
use Duyler\DI\Provider\AbstractProvider class ClassProvider extends AbstractProvider { public function bind(): array { return [ MyClassInterface::class => MyImplemensClass::class, ]; } }
$container->addProviders([ MyClassInterface::class => ClassProvider::class, ]); $yourClassObject = $container->get(YourClass::class);
Make instance with bind
$container->bind([ MyClassInterface::class => MyImplemensClass::class, ]); $yourClassObject = $container->get(YouClass::class);