1
1
<?php
2
2
namespace SparkPost \SendGridCompatibility ;
3
3
4
- class Email
5
- {
4
+ class Email {
6
5
public $ model ;
7
6
8
7
/**
9
8
* Sets up the model for saving the configuration
10
9
*/
11
- public function __construct ()
12
- {
10
+ public function __construct () {
13
11
$ this ->model = array ();
14
12
}
15
13
16
14
/**
17
- * Adds addresses as recipients
18
- *
15
+ * adds addresses as recipients
19
16
* @param string $address
20
17
* @param string $name optional
21
- * @return \SparkPost\SendGridCompatibility\Email
18
+ * @return $this
22
19
*/
23
- public function addTo ($ address , $ name = null )
24
- {
20
+ public function addTo ($ address , $ name = null ) {
25
21
if (!isset ($ this ->model ['recipients ' ])) {
26
22
$ this ->model ['recipients ' ] = array ();
27
23
}
28
24
29
- if (isset ($ name )) {
30
- $ address = array ('address ' => array ('email ' => $ address , 'name ' => $ name ));
25
+ if (isset ($ name )) {
26
+ $ address = array ('address ' => array ('email ' => $ address , 'name ' => $ name ));
31
27
} else {
32
- $ address = array ('address ' => array ('email ' => $ address ));
28
+ $ address = array ('address ' => array ('email ' => $ address ));
33
29
}
34
30
35
31
array_push ($ this ->model ['recipients ' ], $ address );
36
-
37
32
return $ this ;
38
33
}
39
34
40
35
/**
41
- * Explicitly sets a list of addresses
42
- *
43
- * @param array $addresses
44
- * @return \SparkPost\SendGridCompatibility\Email
45
- */
46
- public function setTos (array $ addresses )
47
- {
36
+ * explicitly sets a list of addresses
37
+ * @param array $addresses
38
+ * @return $this
39
+ */
40
+ public function setTos (array $ addresses ) {
48
41
$ this ->model ['recipients ' ] = $ addresses ;
49
-
50
42
return $ this ;
51
43
}
52
44
53
45
/**
54
- * Sets the from address
55
- *
46
+ * sets the from address
56
47
* @param string $address
57
48
* @return $this
58
49
*/
59
- public function setFrom ($ address )
60
- {
50
+ public function setFrom ($ address ) {
61
51
$ this ->model ['from ' ] = array ('email ' => $ address );
62
-
63
52
return $ this ;
64
53
}
65
54
66
55
/**
67
56
* Sets the name for the from address
68
- *
69
57
* @param string $name
70
58
* @return $this
71
59
* @throws \Exception
72
60
*/
73
- public function setFromName ($ name )
74
- {
75
- if (!isset ($ this ->model ['from ' ])) {
61
+ public function setFromName ($ name ) {
62
+ if (!isset ($ this ->model ['from ' ])){
76
63
throw new \Exception ('Must set \'From \' prior to setting \'From Name \'. ' );
77
64
}
78
65
$ this ->model ['from ' ]['name ' ] = $ name ;
79
-
80
66
return $ this ;
81
67
}
82
68
83
69
/**
84
- * Sets the reply to field
85
- *
70
+ * sets the reply to field
86
71
* @param string $address
87
72
* @return $this
88
73
*/
89
- public function setReplyTo ($ address )
90
- {
74
+ public function setReplyTo ($ address ) {
91
75
$ this ->model ['replyTo ' ] = $ address ;
92
-
93
76
return $ this ;
94
77
}
95
78
96
79
/**
97
- * Throws an error because bcc fields are not yet implemented
98
- *
80
+ * throws an error because bcc fields are not yet implemented.
99
81
* @throws \Exception
100
82
* @param string $address
101
83
* @return $this
102
84
*/
103
- public function addBcc ($ address )
104
- {
85
+ public function addBcc ($ address ) {
105
86
throw new \Exception ('Adding bcc recipients is not yet supported, try adding them as a \'to \' address ' );
106
87
}
107
88
108
89
/**
109
- * Sets the subject header
110
- *
90
+ * sets the subject header
111
91
* @param string $subject
112
- * @return \SparkPost\SendGridCompatibility\Email
92
+ * @return $this
113
93
*/
114
- public function setSubject ($ subject )
115
- {
94
+ public function setSubject ($ subject ) {
116
95
$ this ->model ['subject ' ] = $ subject ;
117
-
118
96
return $ this ;
119
97
}
120
98
121
99
/**
122
- * Sets the text body
123
- *
100
+ * sets the text body
124
101
* @param string $text
125
- * @return \SparkPost\SendGridCompatibility\Email
102
+ * @return $this
126
103
*/
127
- public function setText ($ text )
128
- {
104
+ public function setText ($ text ) {
129
105
$ this ->model ['text ' ] = $ text ;
130
-
131
106
return $ this ;
132
107
}
133
108
134
109
/**
135
- * Sets the html body
136
- *
110
+ * sets the html body
137
111
* @param string $html
138
- * @return \SparkPost\SendGridCompatibility\Email
112
+ * @return $this
139
113
*/
140
- public function setHtml ($ html )
141
- {
114
+ public function setHtml ($ html ) {
142
115
$ this ->model ['html ' ] = $ html ;
143
-
144
116
return $ this ;
145
117
}
146
118
147
119
/**
148
120
* Throws an exception since adding categories is not yet supported
149
- *
150
- * @throws \Exception
151
121
* @param string $category
152
122
* @throws \Exception
153
123
*/
154
- public function addCategory ($ category )
155
- {
124
+ public function addCategory ($ category ) {
156
125
throw new \Exception ('Adding categories is not yet supported ' );
157
126
}
158
127
159
128
/**
160
129
* Throws an exception since adding attachments is not yet supported
161
- *
162
- * @param mixed $attachment
163
130
* @throws \Exception
131
+ * @param mixed $attachment
164
132
*/
165
- public function addAttachment ($ attachment )
166
- {
133
+ public function addAttachment ($ attachment ) {
167
134
throw new \Exception ('Adding attachments is not yet supported ' );
168
135
}
169
136
170
137
/**
171
138
* Adds transmission level substitution data
172
- *
173
139
* @param string $name
174
140
* @param mixed $values
175
- * @return \SparkPost\SendGridCompatibility\Email
141
+ * @return $this
176
142
*/
177
- public function addSubstitution ($ name , $ values )
178
- {
143
+ public function addSubstitution ($ name , $ values ) {
179
144
if (!isset ($ this ->model ['substitutionData ' ])) {
180
145
$ this ->model ['substitutionData ' ] = array ();
181
146
}
@@ -186,61 +151,49 @@ public function addSubstitution($name, $values)
186
151
187
152
/**
188
153
* Adds transmission level substitution data
189
- *
190
154
* @param string $name
191
155
* @param mixed $values
192
156
*/
193
- public function addSection ($ name , $ values )
194
- {
157
+ public function addSection ($ name , $ values ) {
195
158
$ this ->addSubstitution ($ name , $ values );
196
159
}
197
160
198
161
/**
199
162
* Throws an exception because arguments for third party systems is not supported
200
- *
201
- * @param $key
202
- * @param mixed $value
203
163
* @throws \Exception
164
+ * @param mixed $value
204
165
*/
205
- public function addUniqueArg ($ key , $ value )
206
- {
166
+ public function addUniqueArg ($ key , $ value ) {
207
167
throw new \Exception ('Adding Unique Arguments is not yet supported ' );
208
168
}
209
169
210
170
/**
211
171
* Throws an exception because arguments for third party systems is not supported
212
- *
213
- * @param mixed $values
214
172
* @throws \Exception
173
+ * @param mixed $values
215
174
*/
216
- public function setUniqueArgs (array $ values )
217
- {
175
+ public function setUniqueArgs (array $ values ) {
218
176
throw new \Exception ('Setting Unique Arguments is not yet supported ' );
219
177
}
220
178
221
179
/**
222
180
* Adds custom headers to the email header
223
- *
224
181
* @param string $name
225
182
* @param string $value
226
183
*/
227
- public function addHeader ($ name , $ value )
228
- {
184
+ public function addHeader ($ name , $ value ) {
229
185
if (!isset ($ this ->model ['customHeaders ' ])) {
230
186
$ this ->model ['customHeaders ' ] = array ();
231
187
}
232
188
$ this ->model ['customHeaders ' ][$ name ] = $ value ;
233
189
}
234
190
235
191
/**
236
- * Converts this object to a configuration for a SparkPost transmission
237
- *
192
+ * converts this object to a configuration for a SparkPost transmission
238
193
* @return array
239
194
*/
240
- public function toSparkPostTransmission ()
241
- {
195
+ public function toSparkPostTransmission () {
242
196
return $ this ->model ;
243
197
}
244
198
}
245
-
246
199
?>
0 commit comments