Skip to content

Commit 15ad919

Browse files
committed
Add applyConfig method
1 parent 782a967 commit 15ad919

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Ubiquity/mailer/MailerManager.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MailerManager {
3737
'user' => '',
3838
'password' => '',
3939
'protocol' => 'smtp',
40+
'CharSet' => 'utf-8',
4041
'ns' => 'mail'
4142
];
4243

@@ -67,6 +68,7 @@ public static function start() {
6768
}
6869
$mailer->isHTML(true);
6970
self::$mailer = $mailer;
71+
self::applyConfig($config);
7072
self::$queue = new MailerQueue();
7173
}
7274

@@ -160,6 +162,28 @@ protected static function _getFiles($silent = false) {
160162
return UFileSystem::glob_recursive($typeDir . \DS . '*.php');
161163
}
162164

165+
protected static function applyConfig($config) {
166+
$config = \array_diff_key($config, [
167+
'host' => 0,
168+
'port' => 0,
169+
'protocol' => 0,
170+
'SMTPOptions' => 0,
171+
'auth' => 0,
172+
'password' => 0,
173+
'user' => 0
174+
]);
175+
$reflex = new \ReflectionClass(self::$mailer);
176+
foreach ($config as $k => $v) {
177+
if ($reflex->hasProperty($k)) {
178+
$prop = $reflex->getProperty($k);
179+
$prop->setAccessible(true);
180+
$prop->setValue(self::$mailer, $v);
181+
} elseif ($reflex->hasMethod($k)) {
182+
$reflex->getMethod($k)->invoke(self::$mailer, $v);
183+
}
184+
}
185+
}
186+
163187
/**
164188
* Returns an array of the mail class names
165189
*

0 commit comments

Comments
 (0)