dynamikaweb / yii2-factory-component
yii2 dynamically configurable construct
Installs: 690
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:yii2-extension
Requires
- php: >=5.5.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-11-09 03:03:48 UTC
README
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require dynamikaweb/yii2-factory-component "*"
or add
"dynamikaweb/yii2-factory-component": "*"
to the require
section of your composer.json
file.
How to use
Calling dynamically configured components
Wrong!
Yii::$app->components['mailer'];
Correct!
Yii::$app->get('mailer');
Setup in PHP 7.4 or Higher
common/configs/main.php
<?php use dynamikaweb\fc\FactoryComponent as FC; use common\models\ConfigModel; return [ 'components' => [ // other components ... 'mailer' => FC::build('yii\swiftmailer\Mailer', fn() => [ 'viewPath' => '@common/mail', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => ConfigModel::getInstance()->mail_host, 'username' => ConfigModel::getInstance()->mail_username, 'password' => ConfigModel::getInstance()->mail_password, 'port' => ConfigModel::getInstance()->mail_port, 'encryption' => ConfigModel::getInstance()->mail_encryption ], 'useFileTransport' => false, ]), ] ];
Setup in older´s PHP version
common/configs/main.php
<?php use dynamikaweb\fc\FactoryComponent as FC; use common\models\ConfigModel; return [ 'components' => [ // other components ... 'mailer' => FC::build('yii\swiftmailer\Mailer', function() { $cfg = ConfigModel::getInstance(); return [ 'viewPath' => '@common/mail', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => $cfg->mail_host, 'username' => $cfg->mail_username, 'password' => $cfg->mail_password, 'port' => $cfg->mail_port, 'encryption' => $cfg->mail_encryption ], 'useFileTransport' => false, ]; }), ] ];
This project is under BSD-3-Clause license.