mqwerty/dependency-injection

Simple PSR-11 DI container with autowiring

v1.2.0 2020-07-24 09:23 UTC

README

Test Quality Gate Status Coverage Minimum PHP Version Latest Stable Version

Simple PSR-11 DI container with autowiring

<?php

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;

class Foo
{
    public function __construct(LoggerInterface $logger)
    {
    }
}

$config = [
    'logLevel' => 'info',
    'shared' => [LoggerInterface::class],
    LoggerInterface::class => fn($c) => (new Logger('log'))->pushHandler(
        new StreamHandler(STDERR, $c->get('logLevel'))
    ),
];

$container = new Mqwerty\DI\Container($config);
$container->get(Foo::class);