arikaim/container

Dependency Injection Container

1.1.7 2022-01-05 07:55 UTC

This package is auto-updated.

Last update: 2024-10-09 13:32:30 UTC


README

version: 1.0.0 license: MIT

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