1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: vincent |
||
5 | * Date: 12/14/17 |
||
6 | * Time: 4:54 PM. |
||
7 | */ |
||
8 | |||
9 | namespace CraftedSystems\LaravelSMS; |
||
10 | |||
11 | use Illuminate\Http\Request; |
||
12 | |||
13 | class SMS |
||
14 | { |
||
15 | /** |
||
16 | * SMS Configuration. |
||
17 | * |
||
18 | * @var null|object |
||
19 | */ |
||
20 | protected $config = null; |
||
21 | |||
22 | /** |
||
23 | * Sms Gateway Settings. |
||
24 | * |
||
25 | * @var null|object |
||
26 | */ |
||
27 | protected $settings = null; |
||
28 | |||
29 | /** |
||
30 | * Sms Gateway Name. |
||
31 | * |
||
32 | * @var null|string |
||
33 | */ |
||
34 | protected $gateway = null; |
||
35 | |||
36 | /** |
||
37 | * @var object |
||
38 | */ |
||
39 | protected $object = null; |
||
40 | |||
41 | /** |
||
42 | * SMS constructor. |
||
43 | * |
||
44 | * @throws \Exception |
||
45 | */ |
||
46 | public function __construct() |
||
47 | { |
||
48 | $this->config = config('sms'); |
||
49 | $this->gateway = $this->config['default']; |
||
50 | $this->mapGateway(); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Change the gateway on the fly. |
||
55 | * |
||
56 | * @param $gateway |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function gateway($gateway) |
||
61 | { |
||
62 | $this->gateway = $gateway; |
||
63 | $this->mapGateway(); |
||
64 | |||
65 | return $this; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | *map the gateway that will be used to send. |
||
70 | */ |
||
71 | private function mapGateway() |
||
72 | { |
||
73 | $this->settings = $this->config['gateways'][$this->gateway]; |
||
74 | $class = $this->config['map'][$this->gateway]; |
||
75 | $this->object = new $class($this->settings); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param $recipient |
||
80 | * @param $message |
||
81 | * @param null $params |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
82 | * |
||
83 | * @return mixed |
||
84 | */ |
||
85 | public function send($recipient, $message, $params = null) |
||
86 | { |
||
87 | return $this->object->send($recipient, $message, $params); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * define when the a message is successfully sent. |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function is_successful() |
||
96 | { |
||
97 | return $this->object->is_successful(); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * the message ID as received on the response. |
||
102 | * |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public function getMessageID() |
||
106 | { |
||
107 | return $this->object->getMessageID(); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @return mixed |
||
112 | */ |
||
113 | public function getBalance() |
||
114 | { |
||
115 | return $this->object->getBalance(); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @param Request $request |
||
120 | * |
||
121 | * @return mixed |
||
122 | */ |
||
123 | public function getDeliveryReports(Request $request) |
||
124 | { |
||
125 | return $this->object->getDeliveryReports($request); |
||
126 | } |
||
127 | } |
||
128 |