|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tworzenieweb\SqlProvisioner\Config; |
|
4
|
|
|
|
|
5
|
|
|
class EmailConfig |
|
6
|
|
|
{ |
|
7
|
|
|
const MANDATORY_ENV_VARIABLES = [ |
|
8
|
|
|
self::SMTP_HOST, |
|
9
|
|
|
self::EMAIL_SUBJECT, |
|
10
|
|
|
self::FROM_EMAIL, |
|
11
|
|
|
]; |
|
12
|
|
|
const SMTP_USER = 'SMTP_USER'; |
|
13
|
|
|
const SMTP_PASSWORD = 'SMTP_PASSWORD'; |
|
14
|
|
|
const SMTP_HOST = 'SMTP_HOST'; |
|
15
|
|
|
const EMAIL_SUBJECT = 'EMAIL_SUBJECT'; |
|
16
|
|
|
const FROM_EMAIL = 'FROM_EMAIL'; |
|
17
|
|
|
const FROM_NAME = 'FROM_NAME'; |
|
18
|
|
|
const TO_EMAILS = 'TO_EMAILS'; |
|
19
|
|
|
const SERVER_HOST = 'SERVER_HOST'; |
|
20
|
|
|
|
|
21
|
|
|
/** @var bool */ |
|
22
|
|
|
private $enabled = true; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return $this |
|
26
|
|
|
*/ |
|
27
|
|
|
public function enable() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->enabled = true; |
|
30
|
|
|
|
|
31
|
|
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
|
|
public function disable() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->enabled = false; |
|
40
|
|
|
|
|
41
|
|
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function isEnabled() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->enabled === true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getSmtpUsername(): string |
|
53
|
|
|
{ |
|
54
|
|
|
return getenv(self::SMTP_USER); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function getSmtpPassword(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return getenv(self::SMTP_PASSWORD); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
public function getSmtpHost(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return getenv(self::SMTP_HOST); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
public function getEmailSubject(): string |
|
74
|
|
|
{ |
|
75
|
|
|
return sprintf(getenv(self::EMAIL_SUBJECT), $this->getServerHost()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function getFromEmail(): string |
|
81
|
|
|
{ |
|
82
|
|
|
return getenv(self::FROM_EMAIL); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
public function getFromName(): string |
|
88
|
|
|
{ |
|
89
|
|
|
return getenv(self::FROM_NAME); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
public function getRecipientsList(): array |
|
95
|
|
|
{ |
|
96
|
|
|
return explode(',', getenv(self::TO_EMAILS)); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
public function getServerHost(): string |
|
102
|
|
|
{ |
|
103
|
|
|
return getenv(self::SERVER_HOST); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|