Fix php style

This commit is contained in:
osaajani 2020-01-17 18:19:25 +01:00
parent 461bd9c98d
commit b8bd067dc7
59 changed files with 2307 additions and 1868 deletions

View file

@ -1,5 +1,15 @@
<?php
namespace adapters;
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace adapters;
/**
* Interface for phones adapters
@ -11,80 +21,82 @@
interface AdapterInterface
{
/**
* Classname of the adapter
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public static function meta_classname() : string;
public function __construct(string $number, string $datas);
/**
* Classname of the adapter.
*/
public static function meta_classname(): string;
/**
* Name of the adapter.
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.)
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.).
*/
public static function meta_name() : string;
public static function meta_name(): string;
/**
* Description of the adapter.
* A short description of the service the adapter implements.
*/
public static function meta_description() : string;
public static function meta_description(): string;
/**
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value)
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value).
*/
public static function meta_datas_help() : string;
public static function meta_datas_help(): string;
/**
* List of entries we want in datas for the adapter
* List of entries we want in datas for the adapter.
*
* @return array : Eachline line is a field as an array with keys : name, title, description, required
*/
public static function meta_datas_fields() : array;
public static function meta_datas_fields(): array;
/**
* Does the implemented service support flash smss
* Does the implemented service support flash smss.
*/
public static function meta_support_flash() : bool;
/**
* Does the implemented service support status change
*/
public static function meta_support_status_change() : bool;
public static function meta_support_flash(): bool;
/**
* Adapter constructor, called when instanciated by RaspiSMS
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
* Does the implemented service support status change.
*/
public function __construct (string $number, string $datas);
public static function meta_support_status_change(): bool;
/**
* Method called to send a SMS to a number
* 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
* @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);
public function send(string $destination, string $text, bool $flash = false);
/**
* Method called to read unread SMSs of the number
* Method called to read unread SMSs of the number.
*
* @return array : Array of the sms reads
*/
public function read () : array;
public function read(): array;
/**
* 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
* should be use for exemple to verify that credentials and number are both valid.
*
* @return bool : False on error, true else
*/
public function test () : bool;
public function test(): bool;
/**
* Method called on reception of a status update notification for a SMS
* 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 ();
public static function status_change_callback();
}

View file

@ -1,5 +1,15 @@
<?php
namespace adapters;
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace adapters;
/**
* Interface for phones adapters
@ -11,32 +21,67 @@
class GammuAdapter implements AdapterInterface
{
/**
* Classname of the adapter
* Phone number using the adapter.
*/
public static function meta_classname() : string { return __CLASS__; }
private $number;
/**
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
*/
private $datas;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $number, string $datas)
{
$this->number = $number;
$this->datas = json_decode($datas, true);
}
/**
* Classname of the adapter.
*/
public static function meta_classname(): string
{
return __CLASS__;
}
/**
* Name of the adapter.
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.)
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.).
*/
public static function meta_name() : string { return 'Gammu'; }
public static function meta_name(): string
{
return 'Gammu';
}
/**
* Description of the adapter.
* A short description of the service the adapter implements.
*/
public static function meta_description() : string { return 'Utilisation du logiciel Gammu qui doit être installé sur le serveur et configuré. Voir https://wammu.eu.'; }
public static function meta_description(): string
{
return 'Utilisation du logiciel Gammu qui doit être installé sur le serveur et configuré. Voir https://wammu.eu.';
}
/**
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value)
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value).
*/
public static function meta_datas_help() : string { return 'Fichier de configuration à fournir à Gammu pour utiliser ce modem.'; }
public static function meta_datas_help(): string
{
return 'Fichier de configuration à fournir à Gammu pour utiliser ce modem.';
}
/**
* List of entries we want in datas for the adapter
* List of entries we want in datas for the adapter.
*
* @return array : Every line is a field as an array with keys : name, title, description, required
*/
public static function meta_datas_fields() : array
public static function meta_datas_fields(): array
{
return [
[
@ -55,53 +100,37 @@
}
/**
* Does the implemented service support flash smss
* Does the implemented service support flash smss.
*/
public static function meta_support_flash() : bool { return false ; }
/**
* Does the implemented service support status change
*/
public static function meta_support_status_change() : bool { return false; }
/**
* Phone number using the adapter
*/
private $number;
/**
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
*/
private $datas;
/**
* Adapter constructor, called when instanciated by RaspiSMS
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct (string $number, string $datas)
public static function meta_support_flash(): bool
{
$this->number = $number;
$this->datas = json_decode($datas, true);
return false;
}
/**
* Method called to send a SMS to a number
* Does the implemented service support status change.
*/
public static function meta_support_status_change(): bool
{
return false;
}
/**
* 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
* @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)
public function send(string $destination, string $text, bool $flash = false)
{
if (!$this->unlock_sim())
{
return false;
}
$command_parts = [
'gammu',
'--config',
@ -123,7 +152,7 @@
}
$result = $this->exec_command($command_parts);
if ($result['return'] != 0)
if (0 !== $result['return'])
{
return false;
}
@ -139,15 +168,16 @@
{
$matches = [];
preg_match('#reference=([0-9]+)#u', $line, $matches);
if ($matches[1] ?? false)
{
$uid = $matches[1];
break;
}
}
if ($uid === false)
if (false === $uid)
{
return false;
}
@ -155,12 +185,12 @@
return $uid;
}
/**
* Method called to read SMSs of the number
* Method called to read SMSs of the number.
*
* @return array : Array of the sms reads
*/
public function read () : array
public function read(): array
{
if (!$this->unlock_sim())
{
@ -168,12 +198,12 @@
}
$command_parts = [
PWD . '/bin/gammu_get_unread_sms.py',
PWD.'/bin/gammu_get_unread_sms.py',
escapeshellarg($this->datas['config_file']),
];
$return = $this->exec_command($command_parts);
if ($return['return'] != 0)
if (0 !== $return['return'])
{
return [];
}
@ -182,7 +212,7 @@
foreach ($return['output'] as $line)
{
$decode = json_decode($line, true);
if ($decode === null)
if (null === $decode)
{
continue;
}
@ -198,34 +228,34 @@
return $smss;
}
/**
* 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
* should be use for exemple to verify that credentials and number are both valid.
*
* @return bool : False on error, true else
*/
public function test () : bool
public function test(): bool
{
//Always return true as we cannot test because we would be needing a root account
return true;
}
/**
* Method called on reception of a status update notification for a SMS
* 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 ()
public static function status_change_callback()
{
return false;
}
/**
* Function to unlock pin
* Function to unlock pin.
*
* @return bool : False on error, true else
*/
private function unlock_sim () : bool
private function unlock_sim(): bool
{
if (!$this->datas['pin'])
{
@ -243,7 +273,6 @@
$result = $this->exec_command($command_parts);
//Check security status
$command_parts = [
'gammu',
@ -254,7 +283,7 @@
$result = $this->exec_command($command_parts);
if ($result['return'] != 0)
if (0 !== $result['return'])
{
return false;
}
@ -262,20 +291,20 @@
return $this->search_for_string($result['output'], 'nothing');
}
/**
* Function to execute a command and transmit it to Gammu
* Function to execute a command and transmit it to Gammu.
*
* @param array $command_parts : Commands parts to be join with a space
*
* @return array : ['return' => int:return code of command, 'output' => array:each raw is a line of the output]
*/
private function exec_command (array $command_parts) : array
private function exec_command(array $command_parts): array
{
//Add redirect of error to stdout
$command_parts[] = '2>&1';
$command = implode(' ', $command_parts);
$output = [];
$return_var = null;
exec($command, $output, $return_var);
@ -283,20 +312,21 @@
return ['return' => (int) $return_var, 'output' => $output];
}
/**
* Function to search a string in the output of an executer command
* @param array $output : Text to search in where each raw is a line
* Function to search a string in the output of an executer command.
*
* @param array $output : Text to search in where each raw is a line
* @param string $search : Text to search for
*
* @return bool : True if found, false else
*/
private function search_for_string (array $output, string $search) : bool
private function search_for_string(array $output, string $search): bool
{
$find = false;
foreach ($output as $line)
{
$find = mb_stristr($line, $search);
if ($find !== false)
if (false !== $find)
{
break;
}
@ -304,6 +334,4 @@
return (bool) $find;
}
}

View file

@ -1,6 +1,17 @@
<?php
namespace adapters;
use \Ovh\Api;
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace adapters;
use Ovh\Api;
/**
* Interface for phones adapters
@ -12,32 +23,85 @@
class OvhSmsAdapter implements AdapterInterface
{
/**
* Classname of the adapter
* Phone number using the adapter.
*/
public static function meta_classname() : string { return __CLASS__; }
private $number;
/**
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
*/
private $datas;
/**
* OVH Api instance.
*/
private $api;
/**
* Number formated to be compatible with http query according to the ovh way.
*/
private $formatted_number;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $number, string $datas)
{
$this->number = $number;
$this->formatted_number = str_replace('+', '00', $number);
$this->datas = json_decode($datas, true);
$this->api = new Api(
$this->datas['app_key'],
$this->datas['app_secret'],
$this->datas['endpoint'],
$this->datas['consumer_key']
);
}
/**
* Classname of the adapter.
*/
public static function meta_classname(): string
{
return __CLASS__;
}
/**
* Name of the adapter.
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.)
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.).
*/
public static function meta_name() : string { return 'OVH SMS'; }
public static function meta_name(): string
{
return 'OVH SMS';
}
/**
* Description of the adapter.
* A short description of the service the adapter implements.
*/
public static function meta_description() : string { return 'Solution de SMS proposé par le groupe OVH, https://www.ovhtelecom.fr/sms/.'; }
public static function meta_description(): string
{
return 'Solution de SMS proposé par le groupe OVH, https://www.ovhtelecom.fr/sms/.';
}
/**
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value)
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value).
*/
public static function meta_datas_help() : string { return 'Clefs API OVH, https://api.ovh.com/createToken/index.cgi.'; }
public static function meta_datas_help(): string
{
return 'Clefs API OVH, https://api.ovh.com/createToken/index.cgi.';
}
/**
* List of entries we want in datas for the adapter
* List of entries we want in datas for the adapter.
*
* @return array : Every line is a field as an array with keys : name, title, description, required
*/
public static function meta_datas_fields() : array
public static function meta_datas_fields(): array
{
return [
[
@ -74,70 +138,37 @@
}
/**
* Does the implemented service support flash smss
* Does the implemented service support flash smss.
*/
public static function meta_support_flash() : bool { return false ; }
/**
* Does the implemented service support status change
*/
public static function meta_support_status_change() : bool { return true; }
/**
* Phone number using the adapter
*/
private $number;
/**
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
*/
private $datas;
/**
* OVH Api instance
*/
private $api;
/**
* Number formated to be compatible with http query according to the ovh way
*/
private $formatted_number;
/**
* Adapter constructor, called when instanciated by RaspiSMS
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct (string $number, string $datas)
public static function meta_support_flash(): bool
{
$this->number = $number;
$this->formatted_number = str_replace('+', '00', $number);
$this->datas = json_decode($datas, true);
$this->api = new Api(
$this->datas['app_key'],
$this->datas['app_secret'],
$this->datas['endpoint'],
$this->datas['consumer_key']
);
return false;
}
/**
* Method called to send a SMS to a number
* Does the implemented service support status change.
*/
public static function meta_support_status_change(): bool
{
return true;
}
/**
* 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
* @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)
public function send(string $destination, string $text, bool $flash = false)
{
try
try
{
$success = true;
$endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/jobs';
$endpoint = '/sms/'.$this->datas['service_name'].'/virtualNumbers/'.$this->formatted_number.'/jobs';
$params = [
'message' => $text,
'receivers' => [$destination],
@ -145,14 +176,15 @@
$response = $this->api->post($endpoint, $params);
$nb_invalid_receivers = count(($response['invalidReceivers'] ?? []));
$nb_invalid_receivers = \count(($response['invalidReceivers'] ?? []));
if ($nb_invalid_receivers > 0)
{
return false;
}
$uids = $response['ids'] ?? [];
return ($uids[0] ?? false);
return $uids[0] ?? false;
}
catch (\Exception $e)
{
@ -160,21 +192,21 @@
}
}
/**
* Method called to read SMSs of the number
* Method called to read SMSs of the number.
*
* @return array : Array of the sms reads
*/
public function read () : array
public function read(): array
{
try
try
{
$success = true;
$endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/incoming';
$endpoint = '/sms/'.$this->datas['service_name'].'/virtualNumbers/'.$this->formatted_number.'/incoming';
$uids = $this->api->get($endpoint);
if (!is_array($uids) || !$uids)
if (!\is_array($uids) || !$uids)
{
return [];
}
@ -182,7 +214,7 @@
$received_smss = [];
foreach ($uids as $uid)
{
$endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/incoming/' . $uid;
$endpoint = '/sms/'.$this->datas['service_name'].'/virtualNumbers/'.$this->formatted_number.'/incoming/'.$uid;
$sms_details = $this->api->get($endpoint);
if (!isset($sms_details['creationDatetime'], $sms_details['message'], $sms_details['sender']))
@ -198,7 +230,7 @@
];
//Remove the sms to prevent double reading as ovh do not offer a filter for unread messages only
$endpoint = '/sms/' . $this->datas['service_name'] . '/virtualNumbers/' . $this->formatted_number . '/incoming/' . $uid;
$endpoint = '/sms/'.$this->datas['service_name'].'/virtualNumbers/'.$this->formatted_number.'/incoming/'.$uid;
$this->api->delete($endpoint);
}
@ -210,29 +242,28 @@
}
}
/**
* 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
* should be use for exemple to verify that credentials and number are both valid.
*
* @return bool : False on error, true else
*/
public function test () : bool
public function test(): bool
{
try
try
{
$success = true;
//Check service name
$endpoint = '/sms/' . $this->datas['service_name'];
$response = $this->api->get($endpoint);
$success = $success && (bool) $response;
//Check virtualnumber
$endpoint = '/sms/virtualNumbers/' . $this->formatted_number;
$endpoint = '/sms/'.$this->datas['service_name'];
$response = $this->api->get($endpoint);
$success = $success && (bool) $response;
return $success;
//Check virtualnumber
$endpoint = '/sms/virtualNumbers/'.$this->formatted_number;
$response = $this->api->get($endpoint);
return $success && (bool) $response;
}
catch (\Exception $e)
{
@ -240,17 +271,17 @@
}
}
/**
* Method called on reception of a status update notification for a SMS
* 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 ()
public static function status_change_callback()
{
$uid = $_GET['id'] ?? false;
$dlr = $_GET['dlr'] ?? false;
if ($uid === false || $dlr === false)
if (false === $uid || false === $dlr)
{
return false;
}
@ -259,15 +290,16 @@
{
case 1:
$status = 'delivered';
break;
break;
case 2:
case 16:
$status = 'failed';
break;
default:
$status = 'unknown';
break;
}

View file

@ -1,5 +1,15 @@
<?php
namespace adapters;
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace adapters;
/**
* Interface for phones adapters
@ -11,46 +21,7 @@
class TestAdapter implements AdapterInterface
{
/**
* Classname of the adapter
*/
public static function meta_classname() : string { return __CLASS__; }
/**
* Name of the adapter.
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.)
*/
public static function meta_name() : string { return 'Test'; }
/**
* Description of the adapter.
* A short description of the service the adapter implements.
*/
public static function meta_description() : string { return 'A test adaptater that do not actually send or receive any message.'; }
/**
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value)
*/
public static function meta_datas_help() : string { return 'No datas.'; }
/**
* List of entries we want in datas for the adapter
* @return array : Eachline line is a field as an array with keys : name, title, description, required
*/
public static function meta_datas_fields() : array { return []; }
/**
* Does the implemented service support flash smss
*/
public static function meta_support_flash() : bool { return true ; }
/**
* Does the implemented service support status change
*/
public static function meta_support_status_change() : bool { return true; }
/**
* Phone number using the adapter
* Phone number using the adapter.
*/
private $number;
@ -59,53 +30,113 @@
*/
private $datas;
/**
* Path for the file to read sms as a json from.
*/
private $test_file_read = PWD_DATAS.'/test_read_sms.json';
/**
* Path for the file to read sms as a json from
* Path for the file to write sms as a json in.
*/
private $test_file_read = PWD_DATAS . '/test_read_sms.json';
/**
* Path for the file to write sms as a json in
*/
private $test_file_write = PWD_DATAS . '/test_write_sms.json';
private $test_file_write = PWD_DATAS.'/test_write_sms.json';
/**
* Adapter constructor, called when instanciated by RaspiSMS
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct (string $number, string $datas)
public function __construct(string $number, string $datas)
{
$this->number = $number;
$this->datas = $datas;
}
/**
* Method called to send a SMS to a number
* Classname of the adapter.
*/
public static function meta_classname(): string
{
return __CLASS__;
}
/**
* Name of the adapter.
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.).
*/
public static function meta_name(): string
{
return 'Test';
}
/**
* Description of the adapter.
* A short description of the service the adapter implements.
*/
public static function meta_description(): string
{
return 'A test adaptater that do not actually send or receive any message.';
}
/**
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value).
*/
public static function meta_datas_help(): string
{
return 'No datas.';
}
/**
* List of entries we want in datas for the adapter.
*
* @return array : Eachline line is a field as an array with keys : name, title, description, required
*/
public static function meta_datas_fields(): array
{
return [];
}
/**
* Does the implemented service support flash smss.
*/
public static function meta_support_flash(): bool
{
return true;
}
/**
* Does the implemented service support status change.
*/
public static function meta_support_status_change(): bool
{
return true;
}
/**
* 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
* @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)
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);
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
* Method called to read SMSs of the number.
*
* @return array : Array of the sms reads
*/
public function read () : array
public function read(): array
{
$file_contents = file_get_contents($this->test_file_read);
@ -119,7 +150,7 @@
foreach ($smss as $key => $sms)
{
$decode_sms = json_decode($sms, true);
if (NULL === $decode_sms)
if (null === $decode_sms)
{
continue;
}
@ -129,24 +160,24 @@
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
* should be use for exemple to verify that credentials and number are both valid.
*
* @return bool : False on error, true else
*/
public function test () : bool
public function test(): bool
{
return true;
}
/**
* Method called on reception of a status update notification for a SMS
* 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 ()
public static function status_change_callback()
{
$uid = $_GET['uid'] ?? false;
$status = $_GET['status'] ?? false;
@ -163,16 +194,17 @@
switch ($status)
{
case 'delivered' :
case 'delivered':
$return['status'] = 'delivered';
break;
case 'failed' :
$return['status'] = 'failed';
break;
default :
break;
case 'failed':
$return['status'] = 'failed';
break;
default:
$return['status'] = 'unknown';
break;
}