Skip to content

Commit c6cdd43

Browse files
committed
Default account config fallback added
1 parent 5424c17 commit c6cdd43

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1414
### Affected Classes
1515
- NaN
1616

17+
## [2.1.1] - 2020-09-23
18+
### Fixed
19+
- Missing default config parameter added
20+
21+
### Added
22+
- Default account config fallback added
23+
24+
### Affected Classes
25+
- [Client::class](src/Client.php)
26+
1727
## [2.1.0] - 2020-09-22
1828
### Fixed
1929
- Quota handling fixed

src/Client.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
class Client {
3434
use HasEvents;
3535

36-
3736
/**
3837
* @var boolean|Protocol
3938
*/
@@ -103,14 +102,6 @@ class Client {
103102
*/
104103
protected $active_folder = false;
105104

106-
/**
107-
* All valid and available account config parameters
108-
*
109-
* @var array $validConfigKeys
110-
*/
111-
protected $valid_config_keys = ['host', 'port', 'encryption', 'validate_cert', 'username', 'password', 'protocol',
112-
'authentication'];
113-
114105
/**
115106
* @var string $default_message_mask
116107
*/
@@ -121,6 +112,20 @@ class Client {
121112
*/
122113
protected $default_attachment_mask = AttachmentMask::class;
123114

115+
/**
116+
* @var array $default_account_config
117+
*/
118+
protected $default_account_config = [
119+
'host' => 'localhost',
120+
'port' => 993,
121+
'protocol' => 'imap',
122+
'encryption' => 'ssl',
123+
'validate_cert' => true,
124+
'username' => '',
125+
'password' => '',
126+
'authentication' => null,
127+
];
128+
124129
/**
125130
* Client constructor.
126131
* @param array $config
@@ -151,13 +156,28 @@ public function setConfig(array $config) {
151156
$default_account = ClientManager::get('default');
152157
$default_config = ClientManager::get("accounts.$default_account");
153158

154-
foreach ($this->valid_config_keys as $key) {
155-
$this->$key = isset($config[$key]) ? $config[$key] : $default_config[$key];
159+
foreach ($this->default_account_config as $key => $value) {
160+
$this->setAccountConfig($key, $config, $default_config);
156161
}
157162

158163
return $this;
159164
}
160165

166+
/**
167+
* @param string $key
168+
* @param array $config
169+
* @param array $default_config
170+
*/
171+
private function setAccountConfig($key, $config, $default_config){
172+
$value = $this->default_account_config[$key];
173+
if(isset($config[$key])) {
174+
$value = $config[$key];
175+
}elseif(isset($default_config[$key])) {
176+
$value = $default_config[$key];
177+
}
178+
$this->$key = $value;
179+
}
180+
161181
/**
162182
* Look for a possible events in any available config
163183
* @param $config

0 commit comments

Comments
 (0)