mertvetsky/yii2-simple-container-configurator

Simple extension for register Yii2 class definition

0.1 2016-09-10 23:01 UTC

This package is auto-updated.

Last update: 2024-04-20 20:50:32 UTC


README

Just add to config components block

        'containerConfig' => [
             'class' => \mertvetsky\yii2SimpleContainerConfigurator\SimpleContainerConfig::class,
             'file' => __DIR__ . '/services.php',
        ],

and 'containerConfig' to bootstrap block.

Then create config/services.php file with your services definitions like

<?php

return [
    'smth' => [
        'class'     => \app\lib\smth\Smth::class,
        'singleton' => false,
        'message'   => 'from config' // or any defined as public field in your class
    ],
    'pew'  => [
        'class' => \app\lib\smth\Pewpew::class
    ]
];

After that you can use your configured classes at any \yii\base\Component child class

    public function __construct($id, Module $module, Smth $smth, Pewpew $pewpew, array $config = [])
    {
        parent::__construct($id, $module, $config);
        $this->smth = $smth;
        $this->pewpew = $pewpew;
    }