number = $number; $this->datas = $datas; } /** * Method called to send a SMS to a number * @param string $destination : Phone number to send the sms to * @param string $text : Text of the SMS to send * @param bool $flash : Is the SMS a Flash SMS * @return mixed Uid of the sended message if send, False else */ public function send (string $destination, string $text, bool $flash = false) { $uid = uniqid(); $at = (new \DateTime())->format('Y-m-d H:i:s'); file_put_contents($this->test_file_write, json_encode(['uid' => $uid, 'at' => $at, 'destination' => $destination, 'text' => $text, 'flash' => $flash]) . "\n", FILE_APPEND); return uniqid(); } /** * Method called to read SMSs of the number * @return array : Array of the sms reads */ public function read () : array { $file_contents = file_get_contents($this->test_file_read); //Empty file to avoid dual read file_put_contents($this->test_file_read, ''); $smss = explode("\n", $file_contents); $return = []; foreach ($smss as $key => $sms) { $decode_sms = json_decode($sms, true); if (NULL === $decode_sms) { continue; } $return[] = $decode_sms; } return $return; } /** * Method called to verify if the adapter is working correctly * should be use for exemple to verify that credentials and number are both valid * @return boolean : False on error, true else */ public function test () : bool { return true; } /** * Method called on reception of a status update notification for a SMS * @return mixed : False on error, else array ['uid' => uid of the sms, 'status' => New status of the sms ('unknown', 'delivered', 'failed')] */ public static function status_change_callback () { $uid = $_GET['uid'] ?? false; $status = $_GET['status'] ?? false; if (!$uid || !$status) { return false; } $return = [ 'uid' => $uid, 'status' => 'unknown', ]; switch ($status) { case 'delivered' : $return['status'] = 'delivered'; break; case 'failed' : $return['status'] = 'failed'; break; default : $return['status'] = 'unknown'; break; } return $return; } }