7
7
use Linkstreet \LaravelSms \Contracts \ResponseInterface ;
8
8
use Linkstreet \LaravelSms \Exceptions \AdapterException ;
9
9
use Linkstreet \LaravelSms \Exceptions \DeviceException ;
10
+ use Linkstreet \LaravelSms \Exceptions \MessageException ;
10
11
use Linkstreet \LaravelSms \Model \Device ;
11
12
12
13
/**
@@ -25,6 +26,11 @@ class SmsManager
25
26
*/
26
27
private $ device ;
27
28
29
+ /**
30
+ * @var string
31
+ */
32
+ private $ message ;
33
+
28
34
/**
29
35
* @var array
30
36
*/
@@ -49,6 +55,7 @@ public static function create(array $config)
49
55
}
50
56
51
57
/**
58
+ * Set connection
52
59
* @param string $connection
53
60
* @return self
54
61
* @throws AdapterException
@@ -65,8 +72,7 @@ public function connection(string $connection): self
65
72
}
66
73
67
74
/**
68
- * Add the device collection
69
- *
75
+ * Add device
70
76
* @param \Linkstreet\LaravelSms\Model\Device $device
71
77
* @return self
72
78
*/
@@ -78,21 +84,54 @@ public function to(Device $device): self
78
84
}
79
85
80
86
/**
81
- * Send the message
87
+ * Add message
82
88
* @param string $message
89
+ * @return $this
90
+ */
91
+ public function message (string $ message ): self
92
+ {
93
+ $ this ->message = $ message ;
94
+
95
+ return $ this ;
96
+ }
97
+
98
+ /**
99
+ * Dispatch the sms message via adapter
83
100
* @return ResponseInterface
84
101
* @throws AdapterException
85
102
* @throws DeviceException
103
+ * @throws MessageException
86
104
*/
87
- public function send ( string $ message ): ResponseInterface
105
+ public function dispatch ( ): ResponseInterface
88
106
{
89
107
if (null === $ this ->device ) {
90
108
throw DeviceException::notFound ();
91
109
}
92
110
111
+ if (null === $ this ->message ) {
112
+ throw MessageException::notFound ();
113
+ }
114
+
93
115
$ this ->connection = $ this ->connection ?? $ this ->resolveConnection ($ this ->device );
94
116
95
- return $ this ->getAdapter ($ this ->connection )->send ($ this ->device , $ message );
117
+ return $ this ->getAdapter ($ this ->connection )->send ($ this ->device , $ this ->message );
118
+ }
119
+
120
+ /**
121
+ * Send a sms
122
+ * @param Device $device
123
+ * @param string $message
124
+ * @return ResponseInterface
125
+ * @throws AdapterException
126
+ * @throws DeviceException
127
+ * @throws MessageException
128
+ */
129
+ public function send (Device $ device , string $ message ): ResponseInterface
130
+ {
131
+ $ this ->device = $ device ;
132
+ $ this ->message = $ message ;
133
+
134
+ return $ this ->dispatch ();
96
135
}
97
136
98
137
/**
0 commit comments