arikaim / container
Dependency Injection Container
Fund package maintenance!
arikaim
Open Collective
Ko Fi
Requires
- php: ^7.3|^8.0
- psr/container: ^1.0.0
README
Mini Dependency Injection Container
PSR-11 compatibility
Installation
composer require arikaim/container
Usage
use Arikaim\Container\Container; $container = new Container();
Add service to container
$container['service'] = function() { echo "Service example"; }; $container->add('service_add',function() { echo "Service add example"; }); $container->add('date',function () { return new \DateTime(); }); $date = $container['date']; echo $date->format('Y-m-d');
Add parameters
$container['config'] = "Config value";
Replace service
$container->replace('service',function() { echo "Replace Service"; });
Psr-11 compatibility implement the PSR-11 ContainerInterface
$servcie = $container->get('service'); if ($container->has('service')) { \\ Service exists }
License
MIT License