|
|
@ -46,19 +46,23 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont |
|
|
|
* @var array configuration, which should be applied by default to any new created |
|
|
|
* @var array configuration, which should be applied by default to any new created |
|
|
|
* email message instance. |
|
|
|
* email message instance. |
|
|
|
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available: |
|
|
|
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available: |
|
|
|
* - 'from' invokes [[MessageInterface::from()]] |
|
|
|
* - 'from' argument for [[MessageInterface::from()]] |
|
|
|
* - 'to' invokes [[MessageInterface::to()]] |
|
|
|
* - 'to' argument for [[MessageInterface::to()]] |
|
|
|
* - 'cc' invokes [[MessageInterface::cc()]] |
|
|
|
* - 'cc' argument for [[MessageInterface::cc()]] |
|
|
|
* - 'bcc' invokes [[MessageInterface::bcc()]] |
|
|
|
* - 'bcc' argument for [[MessageInterface::bcc()]] |
|
|
|
* - 'subject' invokes [[MessageInterface::subject()]] |
|
|
|
* - 'subject' argument for [[MessageInterface::subject()]] |
|
|
|
* - 'text' invokes [[MessageInterface::text()]] |
|
|
|
* - 'text' argument for [[MessageInterface::text()]] |
|
|
|
* - 'html' invokes [[MessageInterface::html()]] |
|
|
|
* - 'html' argument for [[MessageInterface::html()]] |
|
|
|
|
|
|
|
* - 'renderText' list of arguments for [[MessageInterface::renderText()]] |
|
|
|
|
|
|
|
* - 'renderHtml' list of arguments for [[MessageInterface::renderHtml()]] |
|
|
|
|
|
|
|
* - 'body' list of arguments for [[MessageInterface::body()]] |
|
|
|
* For example: |
|
|
|
* For example: |
|
|
|
* ~~~ |
|
|
|
* ~~~ |
|
|
|
* array( |
|
|
|
* array( |
|
|
|
* 'charset' => 'UTF-8', |
|
|
|
* 'charset' => 'UTF-8', |
|
|
|
* 'from' => 'noreply@mydomain.com', |
|
|
|
* 'from' => 'noreply@mydomain.com', |
|
|
|
* 'bcc' => 'email.test@mydomain.com', |
|
|
|
* 'bcc' => 'email.test@mydomain.com', |
|
|
|
|
|
|
|
* 'renderText' => ['default/text', ['companyName' => 'YiiApp']], |
|
|
|
* ) |
|
|
|
* ) |
|
|
|
* ~~~ |
|
|
|
* ~~~ |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -118,7 +122,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont |
|
|
|
if (!array_key_exists('class', $config)) { |
|
|
|
if (!array_key_exists('class', $config)) { |
|
|
|
$config['class'] = $this->messageClass; |
|
|
|
$config['class'] = $this->messageClass; |
|
|
|
} |
|
|
|
} |
|
|
|
$configMethodNames = [ |
|
|
|
$directSetterNames = [ |
|
|
|
'from', |
|
|
|
'from', |
|
|
|
'to', |
|
|
|
'to', |
|
|
|
'cc', |
|
|
|
'cc', |
|
|
@ -127,17 +131,30 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont |
|
|
|
'text', |
|
|
|
'text', |
|
|
|
'html', |
|
|
|
'html', |
|
|
|
]; |
|
|
|
]; |
|
|
|
$methodBasedConfig = []; |
|
|
|
$setupMethodNames = [ |
|
|
|
|
|
|
|
'renderText', |
|
|
|
|
|
|
|
'renderHtml', |
|
|
|
|
|
|
|
'body', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$directSetterConfig = []; |
|
|
|
|
|
|
|
$setupMethodConfig = []; |
|
|
|
foreach ($config as $name => $value) { |
|
|
|
foreach ($config as $name => $value) { |
|
|
|
if (in_array($name, $configMethodNames, true)) { |
|
|
|
if (in_array($name, $directSetterNames, true)) { |
|
|
|
$methodBasedConfig[$name] = $value; |
|
|
|
$directSetterConfig[$name] = $value; |
|
|
|
|
|
|
|
unset($config[$name]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (in_array($name, $setupMethodNames, true)) { |
|
|
|
|
|
|
|
$setupMethodConfig[$name] = $value; |
|
|
|
unset($config[$name]); |
|
|
|
unset($config[$name]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$message = Yii::createObject($config); |
|
|
|
$message = Yii::createObject($config); |
|
|
|
foreach ($methodBasedConfig as $name => $value) { |
|
|
|
foreach ($directSetterConfig as $name => $value) { |
|
|
|
$message->$name($value); |
|
|
|
$message->$name($value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($setupMethodConfig as $method => $arguments) { |
|
|
|
|
|
|
|
call_user_func_array(array($message, $method), $arguments); |
|
|
|
|
|
|
|
} |
|
|
|
return $message; |
|
|
|
return $message; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|