webscooby/container PSR-11 dependency injection container

DI Container

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
    ]
]);
1 0
1 follower
40 downloads
Yii Version: 2.0
License: MIT
Category: Others
Developed by: Lex
Created on: Apr 27, 2021
Last updated: (not set)
Packagist Profile
Github Repository

Related Extensions