1 | <?php |
||
12 | class DbDriver extends DriverAbstract |
||
13 | { |
||
14 | protected $config; |
||
15 | |||
16 | protected $outbox; |
||
17 | |||
18 | protected $multipart; |
||
19 | |||
20 | protected $phone; |
||
21 | |||
22 | protected $data = []; |
||
23 | |||
24 | protected $chunks = []; |
||
25 | |||
26 | public $isLongSms = false; |
||
27 | |||
28 | public $sender; |
||
29 | |||
30 | private $minLongSmsChar = 160; |
||
31 | |||
32 | 20 | public function __construct( |
|
42 | |||
43 | 1 | public function send($phoneNumber, $content, $sender = null, $callback = null) |
|
44 | { |
||
45 | 1 | $this->setDestination($phoneNumber); |
|
46 | 1 | $this->setContent($content); |
|
47 | 1 | $this->setSender($sender); |
|
48 | |||
49 | // Check Destination |
||
50 | 1 | $this->getDestination(); |
|
51 | |||
52 | 1 | $outbox = $this->outbox->create($this->data); |
|
53 | |||
54 | 1 | if (! empty($this->chunks) && ! empty($outbox->ID)) { |
|
|
|||
55 | foreach ($this->chunks as $chunk) { |
||
56 | $chunk['ID'] = $outbox->ID; |
||
57 | $this->multipart->create($chunk); |
||
58 | } |
||
59 | } |
||
60 | 1 | } |
|
61 | |||
62 | 3 | public function setDestination($phoneNumber) |
|
72 | |||
73 | 3 | public function getDestination() |
|
81 | |||
82 | 5 | public function setContent($content) |
|
83 | { |
||
84 | 5 | if (empty($content)) { |
|
85 | 1 | throw CouldNotSendNotification::contentNotProvided(); |
|
86 | } |
||
87 | |||
88 | 4 | $this->content = $content; |
|
89 | |||
90 | 4 | if (strlen($content) > $this->minLongSmsChar) { |
|
91 | 1 | $this->parseLongMessage($content); |
|
92 | 1 | } else { |
|
93 | 3 | $this->data['TextDecoded'] = $content; |
|
94 | } |
||
95 | |||
96 | 4 | return $this; |
|
97 | } |
||
98 | |||
99 | 3 | public function getContent() |
|
107 | |||
108 | 2 | public function setSender($sender = null) |
|
109 | { |
||
110 | 2 | if (empty($sender)) { |
|
111 | 1 | $sender = $this->getDefaultSender(); |
|
112 | } |
||
113 | |||
114 | 1 | $senders = $this->getSendersArray(); |
|
115 | |||
116 | 1 | if (! in_array($sender, $senders)) { |
|
117 | return $this->getSender(); |
||
118 | } |
||
119 | |||
120 | 1 | $this->data['SenderID'] = $this->sender = $sender; |
|
121 | |||
122 | 1 | return $this; |
|
123 | } |
||
124 | |||
125 | 9 | public function getSender() |
|
126 | { |
||
127 | 9 | if (empty($this->sender)) { |
|
128 | 8 | $this->sender = $this->getDefaultSender(); |
|
129 | 6 | } |
|
130 | |||
131 | 7 | return $this->sender; |
|
132 | } |
||
133 | |||
134 | 9 | private function getDefaultSender() |
|
135 | { |
||
136 | 9 | $sender = $this->config->get('services.gammu.sender'); |
|
137 | |||
138 | 9 | $senders = $this->getSendersArray(); |
|
139 | |||
140 | 6 | if (in_array($sender, $senders)) { |
|
141 | 2 | $this->sender = $sender; |
|
142 | |||
143 | 2 | return $this->sender; |
|
144 | } |
||
145 | |||
146 | try { |
||
147 | 4 | return $this->phone->where('Send', 'yes')->firstOrFail()->ID; |
|
148 | } catch (Exception $e) { |
||
149 | throw CouldNotSendNotification::senderNotProvided(); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | 10 | private function getSendersArray() |
|
163 | |||
164 | /** |
||
165 | * Generate UDH part for long SMS. |
||
166 | * |
||
167 | * @link https://en.wikipedia.org/wiki/Concatenated_SMS#Sending_a_concatenated_SMS_using_a_User_Data_Header |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 2 | private function generateUDH($total = 2, $sequence = 2, $ref = 0) |
|
197 | |||
198 | 3 | protected function parseLongMessage($content) |
|
199 | { |
||
200 | 3 | if (strlen($content) <= $this->minLongSmsChar) { |
|
201 | 1 | return $this; |
|
202 | } |
||
236 | } |
||
237 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.