-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailMessageAttachment.php
122 lines (108 loc) · 2.3 KB
/
MailMessageAttachment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
if (! defined('_PS_VERSION_')){
exit();
}
/**
* Represents a mail attachment.
*
* @author Thomas Hunziker
*
*/
class MailMessageAttachment {
private $content;
private $name;
private $mimeType;
/**
* Constructor.
*
* Either the input as defined by Mail::send() for mail attachment
* or a mail attachment. In later case the attachment is copied.
*
* @param array|MailMessageAttachment $input
*/
public function __construct($input = null) {
if ($input instanceof MailMessageAttachment) {
$this->content = $input->content;
$this->name = $input->name;
$this->mimeType = $input->mimeType;
}
else if (is_array($input)) {
if (isset($input['content'])) {
$this->setContent($input['content']);
}
if (isset($input['name'])) {
$this->setName($input['name']);
}
if (isset($input['mime'])) {
$this->setMimeType($input['mime']);
}
}
}
/**
* Returns the attachment content.
*
* @return string
*/
public function getContent(){
return $this->content;
}
/**
* Sets the attachment content. This may be binary data.
*
* @param string $content
* @return MailMessageAttachment
*/
public function setContent($content){
$this->content = $content;
return $this;
}
/**
* Returns the name shown to the customer in the mail message.
*
* @return string
*/
public function getName(){
return $this->name;
}
/**
* Sets the name shown to the customer in the mail message.
*
* @param string $name
* @return MailMessageAttachment
*/
public function setName($name){
$this->name = $name;
return $this;
}
/**
* Returns the mime type of the attachment. E.g. application/pdf, text/html.
*
* @return string
*/
public function getMimeType(){
return $this->mimeType;
}
/**
* Sets the mime type of the mail attachment. E.g. application/pdf, text/html.
*
* @param string $mimeType
* @return MailMessageAttachment
*/
public function setMimeType($mimeType){
$this->mimeType = $mimeType;
return $this;
}
/**
* Returns the attachment as an array. This method is
* need to provide the correct input for Mail::send().
*
* @return array
*/
public function toArray() {
return array(
'content' => $this->getContent(),
'name' => $this->getName(),
'mime' => $this->getMimeType(),
);
}
}