Mini Dependency Injection Container
PSR-11 compatibility
composer require arikaim/container
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
}
MIT License