bnf/di

支持PSR-11和container-interop/service-provider的依赖注入容器

0.1.3 2019-02-09 11:41 UTC

This package is auto-updated.

Last update: 2024-09-09 01:06:03 UTC


README

Scrutinizer Code Quality Build Status Coverage Status

提供 PSR-11container-interop/service-provider 支持。

安装

$ composer require bnf/di:~0.1.0

使用方法

<?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);