Skip to content

Commit 8da5953

Browse files
committed
Can import config from environment variables.
1 parent c3532a1 commit 8da5953

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/MailCatcher.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,37 @@ class MailCatcher extends Module
2525
* Initialize from configuration.
2626
*/
2727
public function _initialize()
28+
{
29+
if (isset($this->config['fromEnv']) && $this->config['fromEnv']) {
30+
$this->loadFromEnv();
31+
} else {
32+
$this->loadFromConfig();
33+
}
34+
35+
if (isset($this->config['resetBeforeEachTest'])) {
36+
$this->resetBeforeEachTest = $this->config['resetBeforeEachTest'];
37+
}
38+
}
39+
40+
private function loadFromEnv()
2841
{
2942
if (isset($this->config['url'])) {
30-
$this->url = trim($this->config['url'], '/');
43+
$this->url = trim(getenv($this->config['url']), '/');
3144
}
3245

3346
if (isset($this->config['port'])) {
34-
$this->port = $this->config['port'];
47+
$this->port = getenv($this->config['port']);
3548
}
49+
}
3650

37-
if (isset($this->config['resetBeforeEachTest'])) {
38-
$this->resetBeforeEachTest = $this->config['resetBeforeEachTest'];
51+
private function loadFromConfig()
52+
{
53+
if (isset($this->config['url'])) {
54+
$this->url = trim($this->config['url'], '/');
55+
}
56+
57+
if (isset($this->config['port'])) {
58+
$this->port = $this->config['port'];
3959
}
4060
}
4161

0 commit comments

Comments
 (0)