mertvetsky / yii2-simple-container-configurator
Simple extension for register Yii2 class definition
Installs: 41
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-10-20 21:50:22 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;
}