|
@@ -0,0 +1,92 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+namespace MirfalahTech\Swift;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+use GuzzleHttp\Client;
|
|
8
|
+use GuzzleHttp\RequestOptions;
|
|
9
|
+use Swift_Events_EventListener;
|
|
10
|
+use Swift_Mime_SimpleMessage;
|
|
11
|
+use Swift_Transport;
|
|
12
|
+
|
|
13
|
+class MirfalahTransport implements Swift_Transport
|
|
14
|
+{
|
|
15
|
+ /**
|
|
16
|
+ * @var string
|
|
17
|
+ */
|
|
18
|
+ protected $apiKey;
|
|
19
|
+
|
|
20
|
+ /**
|
|
21
|
+ * @var string
|
|
22
|
+ */
|
|
23
|
+ protected $secret;
|
|
24
|
+
|
|
25
|
+ /**
|
|
26
|
+ * @var string
|
|
27
|
+ */
|
|
28
|
+ protected $endpoint;
|
|
29
|
+
|
|
30
|
+ /**
|
|
31
|
+ * @var Client
|
|
32
|
+ */
|
|
33
|
+ protected $client;
|
|
34
|
+
|
|
35
|
+ public function __construct($apiKey, $secret, $endpoint)
|
|
36
|
+ {
|
|
37
|
+ $this->apiKey = $apiKey;
|
|
38
|
+ $this->secret = $secret;
|
|
39
|
+ $this->endpoint = $endpoint;
|
|
40
|
+ $this->client = new Client();
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ /**
|
|
44
|
+ * @inheritDoc
|
|
45
|
+ */
|
|
46
|
+ public function isStarted()
|
|
47
|
+ {
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ /**
|
|
51
|
+ * @inheritDoc
|
|
52
|
+ */
|
|
53
|
+ public function start()
|
|
54
|
+ {
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ /**
|
|
58
|
+ * @inheritDoc
|
|
59
|
+ */
|
|
60
|
+ public function stop()
|
|
61
|
+ {
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /**
|
|
65
|
+ * @inheritDoc
|
|
66
|
+ */
|
|
67
|
+ public function ping()
|
|
68
|
+ {
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ /**
|
|
72
|
+ * @inheritDoc
|
|
73
|
+ */
|
|
74
|
+ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
|
|
75
|
+ {
|
|
76
|
+ $body = (string) $message;
|
|
77
|
+ $this->client->post($this->endpoint, [
|
|
78
|
+ RequestOptions::QUERY => [
|
|
79
|
+ 'apiKey' => $this->apiKey,
|
|
80
|
+ 'signature' => hash_hmac('sha1', $body, $this->secret),
|
|
81
|
+ ],
|
|
82
|
+ RequestOptions::BODY => $body,
|
|
83
|
+ ]);
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ /**
|
|
87
|
+ * @inheritDoc
|
|
88
|
+ */
|
|
89
|
+ public function registerPlugin(Swift_Events_EventListener $plugin)
|
|
90
|
+ {
|
|
91
|
+ }
|
|
92
|
+}
|