|
1
|
|
|
<?php namespace nyx\notify\transports\mail; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Mail Message |
|
5
|
|
|
* |
|
6
|
|
|
* @package Nyx\Notify |
|
7
|
|
|
* @version 0.1.0 |
|
8
|
|
|
* @author Michal Chojnacki <[email protected]> |
|
9
|
|
|
* @copyright 2012-2017 Nyx Dev Team |
|
10
|
|
|
* @link https://github.com/unyx/nyx |
|
11
|
|
|
*/ |
|
12
|
|
|
class Message extends \Swift_Message |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var array The Message's views. |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $views = []; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array The data to pass to the Message's views. |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $viewData = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Creates a new Mail Message instance. |
|
26
|
|
|
* |
|
27
|
|
|
* Note: Explicitly not calling (direct) parent constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param array $views The Message's views. |
|
30
|
|
|
* @param string $subject The subject of the Message. |
|
31
|
|
|
* @param string $charset The character set of the Message (defaults to UTF-8). |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(array $views = null, string $subject = null, string $charset = 'UTF-8') |
|
34
|
|
|
{ |
|
35
|
|
|
call_user_func_array( |
|
36
|
|
|
[$this, 'Swift_Mime_SimpleMessage::__construct'], |
|
37
|
|
|
\Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message') |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
if (isset($views)) { |
|
41
|
|
|
$this->setViews($views); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (isset($subject)) { |
|
45
|
|
|
$this->setSubject($subject); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->setCharset($charset); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Returns the Message's views. |
|
53
|
|
|
* |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getViews() : array |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->views; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Sets the Message's views. |
|
63
|
|
|
* |
|
64
|
|
|
* @param array $views The names of the views to associate. |
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setViews(array $views) : Message |
|
68
|
|
|
{ |
|
69
|
|
|
$this->views = $views; |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns the data to pass to the Message's views. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getViewData() : array |
|
80
|
|
|
{ |
|
81
|
|
|
// Always include the Message itself as the 'message' key, unless explicitly overwritten. |
|
82
|
|
|
return $this->viewData + ['message' => $this]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Sets the data to pass to the Message's views. |
|
87
|
|
|
* |
|
88
|
|
|
* @param mixed $key The key the value will be available under or an array of key -> value pairs |
|
89
|
|
|
* when associating multiple values. |
|
90
|
|
|
* @param mixed $value The value to set the specified key as (ignored if the key is an array). |
|
91
|
|
|
* @return $this |
|
92
|
|
|
*/ |
|
93
|
|
|
public function with($key, $value = null) |
|
94
|
|
|
{ |
|
95
|
|
|
if (is_array($key)) { |
|
96
|
|
|
$this->viewData = array_merge($this->viewData, $key); |
|
97
|
|
|
} else { |
|
98
|
|
|
$this->viewData[$key] = $value; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|