|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Gammu\Drivers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
6
|
|
|
use GuzzleHttp\Client; |
|
7
|
|
|
use Illuminate\Support\Facades\Redis; |
|
8
|
|
|
use NotificationChannels\Gammu\Exceptions\CouldNotSendNotification; |
|
9
|
|
|
|
|
10
|
|
|
class RedisDriver extends DriverAbstract |
|
11
|
|
|
{ |
|
12
|
|
|
protected $callback; |
|
13
|
|
|
|
|
14
|
|
|
protected $config; |
|
15
|
|
|
|
|
16
|
|
|
protected $data = []; |
|
17
|
|
|
|
|
18
|
|
|
protected $chunks = []; |
|
19
|
|
|
|
|
20
|
|
|
public $destination; |
|
21
|
|
|
|
|
22
|
|
|
public $content; |
|
23
|
|
|
|
|
24
|
|
|
public $channel; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(Repository $config) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->config = $config; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function send($phoneNumber, $content, $channel = null, $sender = null, $callback = null) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->setCallback($callback); |
|
34
|
|
|
$this->setDestination($phoneNumber); |
|
35
|
|
|
$this->setContent($content); |
|
36
|
|
|
$this->setChannel($channel); |
|
37
|
|
|
|
|
38
|
|
|
Redis::publish($this->channel, json_encode([ |
|
39
|
|
|
'to' => $this->destination, |
|
40
|
|
|
'message' => $this->content, |
|
41
|
|
|
'callback' => $this->callback |
|
42
|
|
|
])); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function setChannel($channel) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->channel = !$channel ? 'gammu-channel' : $channel; |
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setCallback($callback) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->callback = $callback; |
|
54
|
|
|
|
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setDestination($phoneNumber) |
|
59
|
|
|
{ |
|
60
|
|
|
if (empty($phoneNumber)) { |
|
61
|
|
|
throw CouldNotSendNotification::destinationNotProvided(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->destination = trim($phoneNumber); |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getDestination() |
|
70
|
|
|
{ |
|
71
|
|
|
if (empty($this->destination)) { |
|
72
|
|
|
throw CouldNotSendNotification::destinationNotProvided(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->destination; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function setContent($content) |
|
79
|
|
|
{ |
|
80
|
|
|
if (empty($content)) { |
|
81
|
|
|
throw CouldNotSendNotification::contentNotProvided(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->content = $content; |
|
85
|
|
|
|
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getContent() |
|
90
|
|
|
{ |
|
91
|
|
|
if (empty($this->content)) { |
|
92
|
|
|
throw CouldNotSendNotification::contentNotProvided(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $this->content; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|