arikaim/container

Dependency Injection Container

1.1.2 2019-11-14 06:51 UTC

This package is auto-updated.

Last update: 2020-03-14 07:32:30 UTC


README

version: 1.0.0 license: MIT

Arikaim Container

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