1+ <?php
2+ namespace SparkPost \SendGridCompatibility ;
3+
4+ class Email {
5+ public $ model ;
6+
7+ public function __construct () {
8+ $ this ->model = array ();
9+ }
10+
11+ public function addTo ($ address , $ name = null ) {
12+ if (!isset ($ this ->model ['recipients ' ])) {
13+ $ this ->model ['recipients ' ] = array ();
14+ }
15+
16+ if (isset ($ name )) {
17+ $ address = array ('address ' =>array ('email ' =>$ address , 'name ' =>$ name ));
18+ } else {
19+ $ address = array ('address ' =>array ('email ' =>$ address ));
20+ }
21+
22+ array_push ($ this ->model ['recipients ' ], $ address );
23+ return $ this ;
24+ }
25+
26+ public function setTos (array $ addresses ) {
27+ $ this ->model ['recipients ' ] = $ addresses ;
28+ return $ this ;
29+ }
30+
31+ /**
32+ *
33+ * @param string $address
34+ * @return \MessageSystems\SendGridCompatibility\Email
35+ */
36+ public function setFrom ($ address ) {
37+ $ this ->model ['from ' ] = array ('email ' => $ address );
38+ return $ this ;
39+ }
40+
41+ /**
42+ * @param string $name
43+ */
44+ public function setFromName ($ name ) {
45+ if (!isset ($ this ->model ['from ' ])){
46+ throw new \Exception ('Must set "From" prior to setting "From Name". ' );
47+ }
48+ $ this ->model ['from ' ]['name ' ] = $ name ;
49+ return $ this ;
50+ }
51+
52+ /**
53+ *
54+ * @param string $address
55+ * @return \MessageSystems\SendGridCompatibility\Email
56+ */
57+ public function setReplyTo ($ address ) {
58+ $ this ->model ['replyTo ' ] = $ address ;
59+ return $ this ;
60+ }
61+
62+ /**
63+ * TODO: Does this work?
64+ *
65+ *
66+ * @param string $address
67+ * @return \MessageSystems\SendGridCompatibility\Email
68+ */
69+ public function addBcc ($ address ) {
70+ if (!isset ($ this ->model ['bcc ' ])) {
71+ $ this ->model ['bcc ' ] = array ();
72+ }
73+ array_push ($ this ->model ['bcc ' ], $ address );
74+ return $ this ;
75+ }
76+
77+ public function setSubject ($ subject ) {
78+ $ this ->model ['subject ' ] = $ subject ;
79+ return $ this ;
80+ }
81+
82+ public function setText ($ text ) {
83+ $ this ->model ['text ' ] = $ text ;
84+ return $ this ;
85+ }
86+
87+ public function setHtml ($ html ) {
88+ $ this ->model ['html ' ] = $ html ;
89+ return $ this ;
90+ }
91+
92+ public function addCategory ($ category ) {
93+ if (!isset ($ this ->model ['tags ' ])) {
94+ $ this ->model ['tags ' ] = array ();
95+ }
96+ array_push ($ this ->model ['tags ' ], $ category );
97+ return $ this ;
98+ }
99+
100+ /**
101+ *
102+ * @throws Exception
103+ * @param mixed $attachment
104+ */
105+ public function addAttachment ($ attachment ) {
106+ throw new \Exception ('Adding attachments is not yet supported ' );
107+ }
108+
109+ /**
110+ * @desc Sets the name attribute on the most recent set email address
111+ * @param string $name
112+ */
113+ public function addSubstitution ($ name , $ values ) {
114+ if (!isset ($ this ->model ['substitutionData ' ])) {
115+ $ this ->model ['substitutionData ' ] = array ();
116+ }
117+ $ this ->model ['substitutionData ' ][$ name ] = $ values ;
118+
119+ return $ this ;
120+ }
121+
122+ public function addSection ($ name , $ values ) {
123+ $ this ->addSubstitution ($ name , $ values );
124+ }
125+
126+ /**
127+ *
128+ * @throws Exception
129+ * @param mixed $attachment
130+ */
131+ public function addUniqueArg ($ key , $ value ) {
132+ throw new \Exception ('Adding Unique Arguments is not yet supported ' );
133+ }
134+
135+ /**
136+ *
137+ * @throws Exception
138+ * @param mixed $attachment
139+ */
140+ public function setUniqueArgs (array $ values ) {
141+ throw new \Exception ('Setting Unique Arguments is not yet supported ' );
142+ }
143+
144+
145+ public function addHeader ($ name , $ value ) {
146+ if (!isset ($ this ->model ['customHeaders ' ])) {
147+ $ this ->model ['customHeaders ' ] = array ();
148+ }
149+ $ this ->model ['customHeaders ' ][$ name ] = $ value ;
150+ }
151+
152+ public function toMsysTransmission () {
153+ return $ this ->model ;
154+ }
155+ }
156+ ?>
0 commit comments