yii2-simple-container-configurator
Just add to config components
block, (*1)
'containerConfig' => [
'class' => \mertvetsky\yii2SimpleContainerConfigurator\SimpleContainerConfig::class,
'file' => __DIR__ . '/services.php',
],
and 'containerConfig'
to bootstrap
block., (*2)
Then create config/services.php file with your services definitions like, (*3)
<?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, (*4)
public function __construct($id, Module $module, Smth $smth, Pewpew $pewpew, array $config = [])
{
parent::__construct($id, $module, $config);
$this->smth = $smth;
$this->pewpew = $pewpew;
}