1
|
|
|
<?php |
2
|
|
|
namespace SamIT\React\Smtp; |
3
|
|
|
|
4
|
|
|
trait MessageTrait |
5
|
|
|
{ |
6
|
|
|
use \GuzzleHttp\Psr7\MessageTrait; |
7
|
|
|
|
8
|
|
|
protected $recipients = []; |
9
|
|
|
public function withHeader($name, $value) |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
throw new \Exception('SMTP Message does not support replacing headers.'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public function withAddedHeader($name, $value) |
15
|
|
|
{ |
16
|
|
|
$new = clone $this; |
17
|
|
|
$new->headers[] = [$name, $value]; |
18
|
|
|
return $new; |
19
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getHeaderLine($name) { |
|
|
|
|
23
|
|
|
throw new \Exception('SMTP Message does not support merging headers with the same name.'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getHeader($header) |
27
|
|
|
{ |
28
|
|
|
$result = []; |
29
|
|
|
$header = strtolower($header); |
30
|
|
|
foreach($this->headers as list($name, $value)) { |
31
|
|
|
if ($header == strtolower($name)) { |
32
|
|
|
$result[] = [$name, $value]; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
return $result; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getHeaders() { |
39
|
|
|
return $this->headers; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function hasHeader($header) |
43
|
|
|
{ |
44
|
|
|
return !empty($this->getHeader($header)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function withoutHeader($header) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
throw new \Exception('SMTP Message does not support removing headers.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
|
|
public function withRecipient($email, $name = null) |
56
|
|
|
{ |
57
|
|
|
return $this->withRecipients([$email => $name]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function withRecipients(array $recipients) |
61
|
|
|
{ |
62
|
|
|
$new = clone $this; |
63
|
|
|
$new->recipients = $recipients; |
64
|
|
|
return $new; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function withAddedRecipient($email, $name = null) |
68
|
|
|
{ |
69
|
|
|
$new = clone $this; |
70
|
|
|
$new->recipients[$email] = $name; |
71
|
|
|
return $new; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Return an instance with the provided recipients added to the original recipient(s). |
76
|
|
|
* |
77
|
|
|
* This method MUST be implemented in such a way as to retain the |
78
|
|
|
* immutability of the message, and MUST return an instance that has the |
79
|
|
|
* new and/or updated header and value. |
80
|
|
|
* |
81
|
|
|
* @return self |
82
|
|
|
* @param array $recipients Array of email => name pairs. |
83
|
|
|
* @throws \InvalidArgumentException for invalid email. |
84
|
|
|
*/ |
85
|
|
|
public function withAddedRecipients(array $recipients) |
86
|
|
|
{ |
87
|
|
|
$new = clone $this; |
88
|
|
|
$new->recipients = array_merge($this->recipients, $recipients); |
89
|
|
|
return $new; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.