bnf/di

Dependency injection container with PSR-11 and container-interop/service-provider support

0.1.2 2018-03-12 19:30 UTC

README

Scrutinizer Code Quality Build Status Coverage Status

Provides PSR-11 and container-interop/service-provider support.

Installation

$ composer require bnf/di:~0.1.0

Usage

<?php
require 'vendor/autoload.php';

use Bnf\Di\Container;
use Psr\Container\ContainerInterface;
use Interop\Container\ServiceProviderInterface;

$container = new Container([new class implements ServiceProviderInterface {
    public function getFactories(): array
    {
        return [
            stdClass::class => function (ContainerInterface $container): stdClass {
                return new stdClass;
            }
        ];
    }
    public function getExtensions(): array
    {
        return [];
    }
}]);

$class = $container->get(stdClass::class);
var_dump($class);