webscooby/container

PSR-11 dependency injection container

1.0.1 2021-04-27 08:24 UTC

This package is auto-updated.

Last update: 2021-04-27 08:24:28 UTC


README

PSR-11 dependency injection container.

Latest Stable Version Latest Unstable Version Build Status codecov

This repository contains two containers:

  1. CompositeContainer.

    This is a PSR-11 container that works as a link between many other PSR-11 containers.

  2. YiiContainer.

    This is a PSR-11 container that works as a link to Yii2 DI container.

Installation

Use composer.

    composer require webscooby/container

Usage

About PSR-11 Container

CompositeContainer

use Webscooby\Container\CompositeContainer;
use Psr\Container\ContainerInterface;

/**
 * @var ContainerInterface[] $anotherContainers
 */

$container = new CompositeContainer();

foreach ($anotherContainers as $anotherContainer) {
    $container->add($anotherContainer);
}

YiiContainer

Added to yii2

Config:

use Psr\Container\ContainerInterface; 
use Webscooby\Container\YiiContainer;

return [
    'container' => [
        'definitions' => [
            ContainerInterface::class => [
                'class' => YiiContainer::class
            ]
        ]
    ]
];

or Yii::$container:

use Psr\Container\ContainerInterface; 
use Webscooby\Container\YiiContainer;

Yii::$container->setDefinitions([
    ContainerInterface::class => [
        'class' => YiiContainer::class
    ]
]);