fix codestyle
This commit is contained in:
parent
350dbb5b59
commit
adef27f862
|
@ -23,7 +23,7 @@ namespace adapters;
|
|||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||
*
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
*/
|
||||
public function __construct(string $datas);
|
||||
|
||||
|
@ -31,12 +31,12 @@ namespace adapters;
|
|||
* Classname of the adapter.
|
||||
*/
|
||||
public static function meta_classname(): string;
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string;
|
||||
public static function meta_uid(): string;
|
||||
|
||||
/**
|
||||
* Name of the adapter.
|
||||
|
@ -66,18 +66,17 @@ namespace adapters;
|
|||
* Does the implemented service support reading smss.
|
||||
*/
|
||||
public static function meta_support_read(): bool;
|
||||
|
||||
|
||||
/**
|
||||
* Does the implemented service support reception callback.
|
||||
*/
|
||||
public static function meta_support_reception(): bool;
|
||||
|
||||
|
||||
/**
|
||||
* Does the implemented service support status change callback.
|
||||
*/
|
||||
public static function meta_support_status_change(): bool;
|
||||
|
||||
|
||||
/**
|
||||
* Method called to send a SMS to a number.
|
||||
*
|
||||
|
@ -86,10 +85,10 @@ namespace adapters;
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* ?string 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* ?string 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false);
|
||||
|
||||
|
@ -97,18 +96,18 @@ namespace adapters;
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'smss' => Array of the sms reads
|
||||
* [
|
||||
* [
|
||||
* string 'at' => sms reception date,
|
||||
* string 'text' => sms text,
|
||||
* string 'origin' => phone number who sent the sms
|
||||
* ],
|
||||
* ...
|
||||
* ]
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'smss' => Array of the sms reads
|
||||
* [
|
||||
* [
|
||||
* string 'at' => sms reception date,
|
||||
* string 'text' => sms text,
|
||||
* string 'origin' => phone number who sent the sms
|
||||
* ],
|
||||
* ...
|
||||
* ]
|
||||
* ]
|
||||
*/
|
||||
public function read(): array;
|
||||
|
||||
|
@ -126,20 +125,20 @@ namespace adapters;
|
|||
* @return mixed : False on error, else array ['uid' => uid of the sms, 'status' => New status of the sms (\models\Sended::STATUS_UNKNOWN, \models\Sended::STATUS_DELIVERED, \models\Sended::STATUS_FAILED)]
|
||||
*/
|
||||
public static function status_change_callback();
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array;
|
||||
public static function reception_callback(): array;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace adapters;
|
|||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||
*
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
*/
|
||||
public function __construct(string $datas)
|
||||
{
|
||||
|
@ -42,12 +42,12 @@ namespace adapters;
|
|||
{
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'gammu_adapter';
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ namespace adapters;
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does the implemented service support reception callback.
|
||||
*/
|
||||
|
@ -125,7 +125,6 @@ namespace adapters;
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called to send a SMS to a number.
|
||||
*
|
||||
|
@ -134,10 +133,10 @@ namespace adapters;
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* ?string 'uid' => Uid of the sms created on success, null on error
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* ?string 'uid' => Uid of the sms created on success, null on error
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -151,6 +150,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot unlock SIM.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Gammu command failed.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -187,6 +188,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot find output OK.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -208,10 +210,12 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot retrieve sms uid.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['uid'] = $uid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -219,10 +223,10 @@ namespace adapters;
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -236,6 +240,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot unlock sim.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -249,6 +254,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Gammu command return failed.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -292,6 +298,25 @@ namespace adapters;
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to unlock pin.
|
||||
*
|
||||
|
@ -376,24 +401,4 @@ namespace adapters;
|
|||
|
||||
return (bool) $find;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace adapters;
|
||||
|
||||
/**
|
||||
* Octopush SMS service with a shortcode adapter
|
||||
* Octopush SMS service with a shortcode adapter.
|
||||
*/
|
||||
class OctopushShortcodeAdapter implements AdapterInterface
|
||||
{
|
||||
|
@ -27,25 +27,25 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
private $datas;
|
||||
|
||||
/**
|
||||
* Octopush login
|
||||
* Octopush login.
|
||||
*/
|
||||
private $login;
|
||||
|
||||
/**
|
||||
* Octopush api key
|
||||
* Octopush api key.
|
||||
*/
|
||||
private $api_key;
|
||||
|
||||
/**
|
||||
* Sender name to use instead of shortcode
|
||||
* Sender name to use instead of shortcode.
|
||||
*/
|
||||
private $sender;
|
||||
|
||||
/**
|
||||
* Octopush api baseurl
|
||||
* Octopush api baseurl.
|
||||
*/
|
||||
private $api_url = 'https://www.octopush-dm.com/api';
|
||||
|
||||
|
||||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||
*
|
||||
|
@ -69,12 +69,11 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'octopush_shortcode_adapter';
|
||||
}
|
||||
|
@ -95,6 +94,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
public static function meta_description(): string
|
||||
{
|
||||
$credentials_url = 'https://www.octopush-dm.com/api-logins';
|
||||
|
||||
return '
|
||||
Envoi de SMS avec un shortcode en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a>
|
||||
';
|
||||
|
@ -128,7 +128,6 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
<b>Si vous utilisez un expéditeur nommé, le destinataire ne pourra pas répondre.</b>',
|
||||
'required' => false,
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -172,10 +171,10 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -196,7 +195,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
'sms_type' => self::SMS_TYPE_LOWCOST,
|
||||
];
|
||||
|
||||
if ($this->sender !== null)
|
||||
if (null !== $this->sender)
|
||||
{
|
||||
$datas['sms_sender'] = $this->sender;
|
||||
}
|
||||
|
@ -212,25 +211,28 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($response === false)
|
||||
if (false === $response)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'HTTP query failed.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response_decode = json_decode($response, true);
|
||||
if ($response_decode === null)
|
||||
if (null === $response_decode)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Invalid JSON for response.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
|
||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -239,16 +241,19 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot extract SMS uid';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['uid'] = $uid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -257,10 +262,10 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -283,7 +288,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$datas = [
|
||||
'user_login' => $this->login,
|
||||
'api_key' => $this->api_key,
|
||||
|
@ -300,18 +305,18 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($response === false)
|
||||
if (false === $response)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$response_decode = json_decode($response, true);
|
||||
if ($response_decode === null)
|
||||
if (null === $response_decode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
|
||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -338,7 +343,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
$uid = $_POST['message_id'] ?? false;
|
||||
$status = $_POST['status'] ?? false;
|
||||
|
||||
if ($uid === false || $status === false)
|
||||
if (false === $uid || false === $status)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -347,40 +352,40 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
{
|
||||
case 'DELIVERED':
|
||||
$status = \models\Sended::STATUS_DELIVERED;
|
||||
|
||||
break;
|
||||
|
||||
case 'NOT_ALLOWED':
|
||||
case 'INVALID_DESTINATION_ADDRESS':
|
||||
case 'OUT_OF_DATE':
|
||||
case 'EXPIRED':
|
||||
case 'BLACKLISTED_NUMBER':
|
||||
$status = \models\Sended::STATUS_FAILED;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
default:
|
||||
$status = \models\Sended::STATUS_UNKNOWN;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return ['uid' => $uid, 'status' => $status];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
$response = [
|
||||
'error' => false,
|
||||
|
@ -400,6 +405,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'One required data of the callback is missing.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -408,6 +414,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -416,6 +423,7 @@ class OctopushShortcodeAdapter implements AdapterInterface
|
|||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
];
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace adapters;
|
||||
|
||||
/**
|
||||
* Octopush SMS service with a shortcode adapter
|
||||
* Octopush SMS service with a shortcode adapter.
|
||||
*/
|
||||
class OctopushVirtualNumberAdapter implements AdapterInterface
|
||||
{
|
||||
|
@ -27,30 +27,30 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
private $datas;
|
||||
|
||||
/**
|
||||
* Octopush login
|
||||
* Octopush login.
|
||||
*/
|
||||
private $login;
|
||||
|
||||
/**
|
||||
* Octopush api key
|
||||
* Octopush api key.
|
||||
*/
|
||||
private $api_key;
|
||||
|
||||
/**
|
||||
* Number phone to use
|
||||
* Number phone to use.
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* Number phone to use formated for octopush compatibility
|
||||
* Number phone to use formated for octopush compatibility.
|
||||
*/
|
||||
private $formatted_number;
|
||||
|
||||
/**
|
||||
* Octopush api baseurl
|
||||
* Octopush api baseurl.
|
||||
*/
|
||||
private $api_url = 'https://www.octopush-dm.com/api';
|
||||
|
||||
|
||||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||
*
|
||||
|
@ -75,12 +75,11 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'octopush_virtual_number_adapter';
|
||||
}
|
||||
|
@ -101,6 +100,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
public static function meta_description(): string
|
||||
{
|
||||
$credentials_url = 'https://www.octopush-dm.com/api-logins';
|
||||
|
||||
return '
|
||||
Envoi de SMS avec un numéro virtuel en utilisant <a target="_blank" href="https://www.octopush.com/">Octopush</a>. Pour trouver vos clés API Octopush <a target="_blank" href="' . $credentials_url . '">cliquez ici.</a>
|
||||
';
|
||||
|
@ -133,7 +133,6 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
'required' => true,
|
||||
'number' => true,
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -177,10 +176,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -212,25 +211,28 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($response === false)
|
||||
if (false === $response)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'HTTP query failed.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response_decode = json_decode($response, true);
|
||||
if ($response_decode === null)
|
||||
if (null === $response_decode)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Invalid JSON for response.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
|
||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Response indicate error code : ' . $response_decode['error_code'];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -239,16 +241,19 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot extract SMS uid';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['uid'] = $uid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -257,10 +262,10 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -283,7 +288,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$datas = [
|
||||
'user_login' => $this->login,
|
||||
'api_key' => $this->api_key,
|
||||
|
@ -300,18 +305,18 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($response === false)
|
||||
if (false === $response)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$response_decode = json_decode($response, true);
|
||||
if ($response_decode === null)
|
||||
if (null === $response_decode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response_decode['error_code'] != self::ERROR_CODE_OK)
|
||||
if (self::ERROR_CODE_OK !== $response_decode['error_code'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -338,7 +343,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
$uid = $_POST['message_id'] ?? false;
|
||||
$status = $_POST['status'] ?? false;
|
||||
|
||||
if ($uid === false || $status === false)
|
||||
if (false === $uid || false === $status)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -347,40 +352,40 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
{
|
||||
case 'DELIVERED':
|
||||
$status = \models\Sended::STATUS_DELIVERED;
|
||||
|
||||
break;
|
||||
|
||||
case 'NOT_ALLOWED':
|
||||
case 'INVALID_DESTINATION_ADDRESS':
|
||||
case 'OUT_OF_DATE':
|
||||
case 'EXPIRED':
|
||||
case 'BLACKLISTED_NUMBER':
|
||||
$status = \models\Sended::STATUS_FAILED;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
default:
|
||||
$status = \models\Sended::STATUS_UNKNOWN;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return ['uid' => $uid, 'status' => $status];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
$response = [
|
||||
'error' => false,
|
||||
|
@ -400,6 +405,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'One required data of the callback is missing.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -408,6 +414,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Invalid origin number : ' . mb_substr($number, 2);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -416,6 +423,7 @@ class OctopushVirtualNumberAdapter implements AdapterInterface
|
|||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
];
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace adapters;
|
|||
use Ovh\Api;
|
||||
|
||||
/**
|
||||
* OVH SMS service with a shortcode allowing responses
|
||||
* OVH SMS service with a shortcode allowing responses.
|
||||
*/
|
||||
class OvhSmsShortcodeAdapter implements AdapterInterface
|
||||
{
|
||||
|
@ -56,9 +56,9 @@ namespace adapters;
|
|||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'ovh_sms_shortcode_adapter';
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ namespace adapters;
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does the implemented service support reception callback.
|
||||
*/
|
||||
|
@ -160,7 +160,6 @@ namespace adapters;
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called to send a SMS to a number.
|
||||
*
|
||||
|
@ -169,10 +168,10 @@ namespace adapters;
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* ?string 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* ?string 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -206,6 +205,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Invalid receiver';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -214,16 +214,19 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot retrieve uid.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['uid'] = $uid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -232,10 +235,10 @@ namespace adapters;
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -288,6 +291,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +307,7 @@ namespace adapters;
|
|||
try
|
||||
{
|
||||
$success = true;
|
||||
|
||||
|
||||
if ($this->datas['sender'] && (mb_strlen($this->datas['sender']) < 3 || mb_strlen($this->datas['sender'] > 11)))
|
||||
{
|
||||
return false;
|
||||
|
@ -312,9 +316,8 @@ namespace adapters;
|
|||
//Check service name
|
||||
$endpoint = '/sms/' . $this->datas['service_name'];
|
||||
$response = $this->api->get($endpoint);
|
||||
$success = $success && (bool) $response;
|
||||
|
||||
return $success;
|
||||
return $success && (bool) $response;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
|
@ -356,23 +359,22 @@ namespace adapters;
|
|||
|
||||
return ['uid' => $uid, 'status' => $status];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace adapters;
|
|||
use Ovh\Api;
|
||||
|
||||
/**
|
||||
* OVH SMS service with a virtual number adapter
|
||||
* OVH SMS service with a virtual number adapter.
|
||||
*/
|
||||
class OvhSmsVirtualNumberAdapter implements AdapterInterface
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace adapters;
|
|||
private $api;
|
||||
|
||||
/**
|
||||
* Number used
|
||||
* Number used.
|
||||
*/
|
||||
private $number;
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace adapters;
|
|||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||
*
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
*/
|
||||
public function __construct(string $datas)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace adapters;
|
|||
'ovh-eu',
|
||||
$this->datas['consumer_key']
|
||||
);
|
||||
|
||||
|
||||
$this->number = $this->datas['number'];
|
||||
$this->formatted_number = str_replace('+', '00', $this->number);
|
||||
}
|
||||
|
@ -65,13 +65,12 @@ namespace adapters;
|
|||
{
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'ovh_sms_virtual_number_adapter';
|
||||
}
|
||||
|
@ -180,10 +179,10 @@ namespace adapters;
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -210,6 +209,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Invalid receiver';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -218,16 +218,19 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot retrieve uid';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['uid'] = $uid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -236,10 +239,10 @@ namespace adapters;
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -253,8 +256,8 @@ namespace adapters;
|
|||
{
|
||||
$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 $response;
|
||||
}
|
||||
|
@ -286,6 +289,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -354,22 +358,22 @@ namespace adapters;
|
|||
|
||||
return ['uid' => $uid, 'status' => $status];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace adapters;
|
|||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS.
|
||||
*
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
*/
|
||||
public function __construct(string $datas)
|
||||
{
|
||||
|
@ -52,12 +52,12 @@ namespace adapters;
|
|||
{
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'test_adapter';
|
||||
}
|
||||
|
@ -89,8 +89,7 @@ namespace adapters;
|
|||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Does the implemented service support reading smss.
|
||||
*/
|
||||
|
@ -131,10 +130,10 @@ namespace adapters;
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -148,15 +147,16 @@ namespace adapters;
|
|||
|
||||
$at = (new \DateTime())->format('Y-m-d H:i:s');
|
||||
$success = file_put_contents($this->test_file_write, json_encode(['uid' => $uid, 'at' => $at, 'destination' => $destination, 'text' => $text, 'flash' => $flash]) . "\n", FILE_APPEND);
|
||||
if ($success === false)
|
||||
if (false === $success)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot write in file : ' . $this->test_file_write;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
$response['uid'] = $uid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -164,10 +164,10 @@ namespace adapters;
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -177,22 +177,24 @@ namespace adapters;
|
|||
'smss' => [],
|
||||
];
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
$file_contents = file_get_contents($this->test_file_read);
|
||||
if ($file_contents === false)
|
||||
if (false === $file_contents)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot read file : ' . $this->test_file_read;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
//Empty file to avoid dual read
|
||||
$success = file_put_contents($this->test_file_read, '');
|
||||
if ($success === false)
|
||||
if (false === $success)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = 'Cannot write in file : ' . $this->test_file_read;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -215,6 +217,7 @@ namespace adapters;
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +235,6 @@ namespace adapters;
|
|||
|
||||
/**
|
||||
* Method called on reception of a status update notification for a SMS.
|
||||
*
|
||||
*/
|
||||
public static function status_change_callback()
|
||||
{
|
||||
|
@ -267,23 +269,22 @@ namespace adapters;
|
|||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace adapters;
|
|||
use Twilio\Rest\Client;
|
||||
|
||||
/**
|
||||
* Twilio SMS service with a virtual number adapter
|
||||
* Twilio SMS service with a virtual number adapter.
|
||||
*/
|
||||
class TwilioVirtualNumberAdapter implements AdapterInterface
|
||||
{
|
||||
|
@ -24,17 +24,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
private $datas;
|
||||
|
||||
/**
|
||||
* Twilio Api client
|
||||
* Twilio Api client.
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Twilio virtual number to use
|
||||
* Twilio virtual number to use.
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* Callback address Twilio must call on SMS status change
|
||||
* Callback address Twilio must call on SMS status change.
|
||||
*/
|
||||
private $status_change_callback;
|
||||
|
||||
|
@ -65,12 +65,11 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uniq name of the adapter
|
||||
* It should be the classname of the adapter un snakecase
|
||||
* It should be the classname of the adapter un snakecase.
|
||||
*/
|
||||
public static function meta_uid() : string
|
||||
public static function meta_uid(): string
|
||||
{
|
||||
return 'twilio_virtual_number_adapter';
|
||||
}
|
||||
|
@ -174,10 +173,10 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'uid' => Uid of the sms created on success
|
||||
* ]
|
||||
*/
|
||||
public function send(string $destination, string $text, bool $flash = false)
|
||||
{
|
||||
|
@ -198,20 +197,23 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
]
|
||||
);
|
||||
|
||||
if ($message->errorCode !== null)
|
||||
if (null !== $message->errorCode)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $message->errorMessage;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['uid'] = $message->sid;
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -220,10 +222,10 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
* Method called to read SMSs of the number.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
* bool 'error' => false if no error, true else
|
||||
* ?string 'error_message' => null if no error, else error message
|
||||
* array 'sms' => Array of the sms reads
|
||||
* ]
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
|
@ -241,7 +243,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
|
||||
foreach ($messages as $record)
|
||||
{
|
||||
if ($record->direction != 'inbound')
|
||||
if ('inbound' !== $record->direction)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -265,6 +267,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
{
|
||||
$response['error'] = true;
|
||||
$response['error_message'] = $t->getMessage();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +287,7 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
foreach ($phone_numbers as $record)
|
||||
{
|
||||
//If not the same number, return false
|
||||
if ($record->phoneNumber != $this->number)
|
||||
if ($record->phoneNumber !== $this->number)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -317,16 +320,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
|
||||
switch ($status)
|
||||
{
|
||||
case 'delivered' :
|
||||
case 'delivered':
|
||||
$status = \models\Sended::STATUS_DELIVERED;
|
||||
break;
|
||||
|
||||
case 'failed' :
|
||||
break;
|
||||
case 'failed':
|
||||
$status = \models\Sended::STATUS_FAILED;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
default:
|
||||
$status = \models\Sended::STATUS_UNKNOWN;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -337,17 +341,17 @@ class TwilioVirtualNumberAdapter implements AdapterInterface
|
|||
* Method called on reception of a sms notification.
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
* bool 'error' => false on success, true on error
|
||||
* ?string 'error_message' => null on success, error message else
|
||||
* array 'sms' => array [
|
||||
* string 'at' : Recepetion date format Y-m-d H:i:s,
|
||||
* string 'text' : SMS body,
|
||||
* string 'origin' : SMS sender,
|
||||
* ]
|
||||
*
|
||||
* ]
|
||||
*/
|
||||
public static function reception_callback() : array
|
||||
public static function reception_callback(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -69,14 +69,14 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Analyse a message to check if it's a command so execute it
|
||||
* Analyse a message to check if it's a command so execute it.
|
||||
*
|
||||
* @param int $id_user : User id to search a command for
|
||||
* @param string $message : Message to analyse
|
||||
*
|
||||
* @return mixed bool|string : false if not a valid command, anonymized message if valid command
|
||||
*/
|
||||
public function analyze_and_process (int $id_user, string $message)
|
||||
public function analyze_and_process(int $id_user, string $message)
|
||||
{
|
||||
if (!ENABLE_COMMAND)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace controllers\internals;
|
|||
{
|
||||
new \daemons\Webhook();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start mailer daemon.
|
||||
*/
|
||||
|
@ -98,13 +98,12 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Update a user status.
|
||||
*
|
||||
* Update a user status
|
||||
*
|
||||
* @param string $email : User email
|
||||
* @param string $email : User email
|
||||
* @param string $status : User status, default \models\User::STATUS_ACTIVE
|
||||
*/
|
||||
public function update_user_status (string $email, string $status)
|
||||
public function update_user_status(string $email, string $status)
|
||||
{
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
||||
$internal_user = new \controllers\internals\User($bdd);
|
||||
|
|
|
@ -148,7 +148,7 @@ namespace controllers\internals;
|
|||
$i = 0;
|
||||
foreach ($line as $key => $value)
|
||||
{
|
||||
$i++;
|
||||
++$i;
|
||||
if ($i < 3)
|
||||
{
|
||||
continue;
|
||||
|
@ -164,7 +164,7 @@ namespace controllers\internals;
|
|||
}
|
||||
$datas = json_encode($datas);
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
$success = $this->create($id_user, $line[array_keys($line)[1]], $line[array_keys($line)[0]], $datas);
|
||||
if ($success)
|
||||
|
|
|
@ -20,20 +20,23 @@ class ExpressionProvider implements ExpressionFunctionProviderInterface
|
|||
{
|
||||
//Override default constant() function to make it return null
|
||||
//This will prevent the use of constant() func to read constants with security impact (such as session, db credentials, etc.)
|
||||
$neutralized_constant = new ExpressionFunction('constant', function ($str) {
|
||||
$neutralized_constant = new ExpressionFunction('constant', function ($str)
|
||||
{
|
||||
return null;
|
||||
}, function ($arguments, $str) {
|
||||
}, function ($arguments, $str)
|
||||
{
|
||||
return null;
|
||||
});
|
||||
|
||||
//Exists must be personnalized because it inverse is_null
|
||||
$exists = new ExpressionFunction('exists', function ($var) {
|
||||
$exists = new ExpressionFunction('exists', function ($var)
|
||||
{
|
||||
return sprintf('!is_null(%1$s)', $str);
|
||||
}, function ($arguments, $var) {
|
||||
return !is_null($var);
|
||||
}, function ($arguments, $var)
|
||||
{
|
||||
return null !== $var;
|
||||
});
|
||||
|
||||
|
||||
return [
|
||||
$neutralized_constant,
|
||||
$exists,
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Return unknown error page
|
||||
* Return unknown error page.
|
||||
*/
|
||||
public function unknown ()
|
||||
public function unknown()
|
||||
{
|
||||
http_response_code(500);
|
||||
$this->render('error/unknown');
|
||||
|
|
|
@ -1,35 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* 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 controllers\internals;
|
||||
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
/**
|
||||
* Mailing class
|
||||
* Mailing class.
|
||||
*/
|
||||
class Mailer extends \descartes\Controller
|
||||
{
|
||||
private $log;
|
||||
private $mail;
|
||||
|
||||
public function __construct ()
|
||||
public function __construct()
|
||||
{
|
||||
$this->log = new Logger('Mailer');
|
||||
$this->log->pushHandler(new StreamHandler(PWD_LOGS . '/mail.log', Logger::DEBUG));
|
||||
|
||||
$this->mail = new PHPMailer(true);
|
||||
$this->mail->CharSet = 'utf-8';
|
||||
$this->mail->SMTPDebug = SMTP::DEBUG_OFF;
|
||||
$this->mail->CharSet = 'utf-8';
|
||||
$this->mail->SMTPDebug = SMTP::DEBUG_OFF;
|
||||
$this->mail->isSMTP();
|
||||
$this->mail->Host = MAIL['SMTP']['HOST'];
|
||||
$this->mail->SMTPAuth = true;
|
||||
$this->mail->Username = MAIL['SMTP']['USER'];
|
||||
$this->mail->Password = MAIL['SMTP']['PASS'];
|
||||
$this->mail->Port = MAIL['SMTP']['PORT'];
|
||||
$this->mail->Host = MAIL['SMTP']['HOST'];
|
||||
$this->mail->SMTPAuth = true;
|
||||
$this->mail->Username = MAIL['SMTP']['USER'];
|
||||
$this->mail->Password = MAIL['SMTP']['PASS'];
|
||||
$this->mail->Port = MAIL['SMTP']['PORT'];
|
||||
$this->mail->setFrom(MAIL['FROM']);
|
||||
|
||||
if (MAIL['SMTP']['TLS'])
|
||||
|
@ -39,15 +47,17 @@ class Mailer extends \descartes\Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Send email
|
||||
* @param array $destinations : Destinations address
|
||||
* @param string $subject : Message subject
|
||||
* @param string $message : Message
|
||||
* @param ?string $alt_message : Alt Message if no html support. Null if message is not html.
|
||||
* @param array $attachments : List of path to attachment files
|
||||
* Send email.
|
||||
*
|
||||
* @param array $destinations : Destinations address
|
||||
* @param string $subject : Message subject
|
||||
* @param string $message : Message
|
||||
* @param ?string $alt_message : Alt Message if no html support. Null if message is not html.
|
||||
* @param array $attachments : List of path to attachment files
|
||||
*
|
||||
* @return bool : false on error, true else
|
||||
*/
|
||||
public function send (array $destinations, string $subject, string $message, ?string $alt_message = null, array $attachments = [])
|
||||
public function send(array $destinations, string $subject, string $message, ?string $alt_message = null, array $attachments = [])
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -66,7 +76,7 @@ class Mailer extends \descartes\Controller
|
|||
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $message;
|
||||
|
||||
|
||||
if ($alt_message)
|
||||
{
|
||||
$mail->isHTML($html);
|
||||
|
@ -74,32 +84,61 @@ class Mailer extends \descartes\Controller
|
|||
}
|
||||
|
||||
$mail->send();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (\Throwable $t)
|
||||
{
|
||||
$this->log->error('Error sending mail : ' . $t);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an email body
|
||||
* @param array $settings : [
|
||||
* string 'type' => Internal RaspiSMS email type,
|
||||
* string 'subject' => Email subject,
|
||||
* string 'template' => Email template to use
|
||||
* ?string 'alt_template' => Template to use for alt message, if null ignore
|
||||
* ]
|
||||
* Enqueue an email for later sending.
|
||||
*
|
||||
* @param string $destination : email address to send email to
|
||||
* @param array $settings : Email settings
|
||||
* @param array $datas : Datas to inject into email template
|
||||
*
|
||||
* @return bool : true on success, false on error
|
||||
*/
|
||||
public function enqueue(string $destination, array $settings, array $datas): bool
|
||||
{
|
||||
$response = $this->generate_body($settings, $datas);
|
||||
|
||||
$message = [
|
||||
'destinations' => [$destination],
|
||||
'subject' => $settings['subject'],
|
||||
'body' => $response['body'],
|
||||
'alt_body' => $response['alt_body'],
|
||||
];
|
||||
|
||||
$error_code = null;
|
||||
$queue = msg_get_queue(QUEUE_ID_EMAIL);
|
||||
$success = msg_send($queue, QUEUE_TYPE_EMAIL, $message, true, true, $error_code);
|
||||
|
||||
return (bool) $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an email body.
|
||||
*
|
||||
* @param array $settings : [
|
||||
* string 'type' => Internal RaspiSMS email type,
|
||||
* string 'subject' => Email subject,
|
||||
* string 'template' => Email template to use
|
||||
* ?string 'alt_template' => Template to use for alt message, if null ignore
|
||||
* ]
|
||||
* @param array : Datas to inject into email template
|
||||
*
|
||||
* @return array [
|
||||
* string 'body' => email body
|
||||
* ?string 'alt_body' => email alternative body if needed
|
||||
* ]
|
||||
* string 'body' => email body
|
||||
* ?string 'alt_body' => email alternative body if needed
|
||||
* ]
|
||||
*/
|
||||
private function generate_body(array $settings, array $datas) : array
|
||||
private function generate_body(array $settings, array $datas): array
|
||||
{
|
||||
//Generate body of email
|
||||
ob_start();
|
||||
|
@ -114,34 +153,10 @@ class Mailer extends \descartes\Controller
|
|||
$this->render($settings['alt_template'], $datas);
|
||||
$alt_body = ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'body' => $body,
|
||||
'body' => $body,
|
||||
'alt_body' => $alt_body,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue an email for later sending
|
||||
* @param string $destination : email address to send email to
|
||||
* @param array $settings : Email settings
|
||||
* @param array $datas : Datas to inject into email template
|
||||
* @return bool : true on success, false on error
|
||||
*/
|
||||
public function enqueue (string $destination, array $settings, array $datas) : bool
|
||||
{
|
||||
$response = $this->generate_body($settings, $datas);
|
||||
|
||||
$message = [
|
||||
'destinations' => [$destination],
|
||||
'subject' => $settings['subject'],
|
||||
'body' => $response['body'],
|
||||
'alt_body' => $response['alt_body'],
|
||||
];
|
||||
|
||||
$error_code = null;
|
||||
$queue = msg_get_queue(QUEUE_ID_EMAIL);
|
||||
$success = msg_send($queue, QUEUE_TYPE_EMAIL, $message, true, true, $error_code);
|
||||
return (bool) $success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a phone by his name
|
||||
* Return a phone by his name.
|
||||
*
|
||||
* @param string $name : Phone name
|
||||
*
|
||||
|
@ -40,10 +40,10 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a phone for a user by a name
|
||||
* Return a phone for a user by a name.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param string $name : Phone name
|
||||
* @param string $name : Phone name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -56,7 +56,7 @@ namespace controllers\internals;
|
|||
* Create a phone.
|
||||
*
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param string $name : The name of the phone
|
||||
* @param string $name : The name of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
|
||||
*
|
||||
|
@ -79,7 +79,7 @@ namespace controllers\internals;
|
|||
*
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param int $id : Phone id
|
||||
* @param string $name : The name of the phone
|
||||
* @param string $name : The name of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param array $adapter_datas : An array of the datas of the adapter (for example credentials for an api)
|
||||
*
|
||||
|
|
|
@ -36,9 +36,9 @@ namespace controllers\internals;
|
|||
* @param int $id_phone : Id of the number the message was send with
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $status : Status of the received message
|
||||
* @param bool $command : Is the sms a command
|
||||
* @param string $origin : Number of the sender
|
||||
* @param string $status : Status of the received message
|
||||
* @param bool $command : Is the sms a command
|
||||
*
|
||||
* @return mixed : false on error, new received id else
|
||||
*/
|
||||
|
@ -203,31 +203,21 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
* Receive a SMS message.
|
||||
*
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model(): \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Received($this->bdd);
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a SMS message
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_phone : Id of the phone the message was sent to
|
||||
* @param $text : Text of the message
|
||||
* @param string $origin : Number of the sender
|
||||
* @param ?string $at : Message reception date, if null use current date
|
||||
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
|
||||
* @param string $origin : Number of the sender
|
||||
* @param ?string $at : Message reception date, if null use current date
|
||||
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if success, true else
|
||||
* ?string 'error_message' => null if success, error message else
|
||||
* ]
|
||||
* bool 'error' => false if success, true else
|
||||
* ?string 'error_message' => null if success, error message else
|
||||
* ]
|
||||
*/
|
||||
public function receive (int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD) : array
|
||||
public function receive(int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD): array
|
||||
{
|
||||
$return = [
|
||||
'error' => false,
|
||||
|
@ -240,8 +230,8 @@ namespace controllers\internals;
|
|||
//Process the message to check plus potentially execute command and anonymize text
|
||||
$internal_command = new Command($this->bdd);
|
||||
$response = $internal_command->analyze_and_process($id_user, $text);
|
||||
if ($response !== false) //Received sms is a command an we must use anonymized text
|
||||
{
|
||||
if (false !== $response)
|
||||
{ //Received sms is a command an we must use anonymized text
|
||||
$is_command = true;
|
||||
$text = $response;
|
||||
}
|
||||
|
@ -251,6 +241,7 @@ namespace controllers\internals;
|
|||
{
|
||||
$return['error'] = true;
|
||||
$return['error_message'] = 'Impossible to insert the sms in database.';
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@ -267,6 +258,19 @@ namespace controllers\internals;
|
|||
|
||||
$internal_user = new User($this->bdd);
|
||||
$internal_user->transfer_received($id_user, $received);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
*
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model(): \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Received($this->bdd);
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace controllers\internals;
|
|||
/**
|
||||
* Create a sended.
|
||||
*
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_phone : Id of the number the message was send with
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
|
@ -111,7 +111,7 @@ namespace controllers\internals;
|
|||
/**
|
||||
* Return sended for an uid and an adapter.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param int $id_user : user id
|
||||
* @param string $uid : Uid of the sended
|
||||
* @param string $adapter : Adapter used to send the message
|
||||
*
|
||||
|
@ -157,32 +157,22 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
* Send a SMS message.
|
||||
*
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model(): \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Sended($this->bdd);
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a SMS message
|
||||
* @param \adapters\AdapterInterface $adapter : Adapter object to use to send the message
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_phone : Id of the phone the message was send with
|
||||
* @param \adapters\AdapterInterface $adapter : Adapter object to use to send the message
|
||||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_phone : Id of the phone the message was send with
|
||||
* @param $text : Text of the message
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $flash : Is the sms a flash. By default false.
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if success, true else
|
||||
* ?string 'error_message' => null if success, error message else
|
||||
* ]
|
||||
* bool 'error' => false if success, true else
|
||||
* ?string 'error_message' => null if success, error message else
|
||||
* ]
|
||||
*/
|
||||
public function send (\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, string $status = \models\Sended::STATUS_UNKNOWN) : array
|
||||
public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, string $status = \models\Sended::STATUS_UNKNOWN): array
|
||||
{
|
||||
$return = [
|
||||
'error' => false,
|
||||
|
@ -198,6 +188,7 @@ namespace controllers\internals;
|
|||
$return['error_message'] = $response['error_message'];
|
||||
$status = \models\Sended::STATUS_FAILED;
|
||||
$this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $status);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@ -213,7 +204,19 @@ namespace controllers\internals;
|
|||
|
||||
$internal_webhook = new Webhook($this->bdd);
|
||||
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND, $sended);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
*
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model(): \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Sended($this->bdd);
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace controllers\internals;
|
|||
|
||||
public function __construct(?\PDO $bdd = null)
|
||||
{
|
||||
if ($bdd === null)
|
||||
if (null === $bdd)
|
||||
{
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
||||
}
|
||||
|
|
|
@ -106,12 +106,11 @@ namespace controllers\internals;
|
|||
{
|
||||
return (bool) $this->model_user->update_email($id, $email);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update user status.
|
||||
*
|
||||
* @param string $id : user id
|
||||
* @param string $id : user id
|
||||
* @param string $status : new status
|
||||
*
|
||||
* @return boolean;
|
||||
|
@ -181,13 +180,13 @@ namespace controllers\internals;
|
|||
/**
|
||||
* Update a user by his id.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $email
|
||||
* @param mixed $password
|
||||
* @param mixed $admin
|
||||
* @param mixed $api_key
|
||||
* @param string $status : User status
|
||||
* @param bool $encrypt_password : Should the password be encrypted, by default true
|
||||
* @param mixed $id
|
||||
* @param mixed $email
|
||||
* @param mixed $password
|
||||
* @param mixed $admin
|
||||
* @param mixed $api_key
|
||||
* @param string $status : User status
|
||||
* @param bool $encrypt_password : Should the password be encrypted, by default true
|
||||
*
|
||||
* @return int : Number of modified user
|
||||
*/
|
||||
|
@ -210,9 +209,9 @@ namespace controllers\internals;
|
|||
* @param mixed $email
|
||||
* @param mixed $password
|
||||
* @param mixed $admin
|
||||
* @param ?string $api_key : The api key of the user, if null generate randomly
|
||||
* @param string $status : User status, default \models\User::STATUS_ACTIVE
|
||||
* @param bool $encrypt_password : Should the password be encrypted, by default true
|
||||
* @param ?string $api_key : The api key of the user, if null generate randomly
|
||||
* @param string $status : User status, default \models\User::STATUS_ACTIVE
|
||||
* @param bool $encrypt_password : Should the password be encrypted, by default true
|
||||
*
|
||||
* @return mixed bool|int : false on error, id of the new user else
|
||||
*/
|
||||
|
@ -255,21 +254,21 @@ namespace controllers\internals;
|
|||
return bin2hex(random_bytes(16));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transfer a received sms to user email
|
||||
* @param int $id_user : User id
|
||||
* Transfer a received sms to user email.
|
||||
*
|
||||
* @param int $id_user : User id
|
||||
* @param array $received : [
|
||||
* int 'id' => sms id,
|
||||
* string 'at' => sms reception date,
|
||||
* string 'text' => sms content,
|
||||
* string 'destination' => id of phone the sms was sent to
|
||||
* string 'origin' => phone number that sent the sms
|
||||
* ]
|
||||
* int 'id' => sms id,
|
||||
* string 'at' => sms reception date,
|
||||
* string 'text' => sms content,
|
||||
* string 'destination' => id of phone the sms was sent to
|
||||
* string 'origin' => phone number that sent the sms
|
||||
* ]
|
||||
*
|
||||
* @return bool : False if no transfer, true else
|
||||
*/
|
||||
public function transfer_received (int $id_user, array $received) : bool
|
||||
public function transfer_received(int $id_user, array $received): bool
|
||||
{
|
||||
$settings = $this->internal_setting->gets_for_user($id_user);
|
||||
|
||||
|
@ -291,6 +290,7 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
$mailer = new Mailer();
|
||||
|
||||
return $mailer->enqueue($user['email'], EMAIL_TRANSFER_SMS, [
|
||||
'at' => $received['at'],
|
||||
'origin' => $received['origin'],
|
||||
|
|
|
@ -87,33 +87,22 @@ class Webhook extends StandardController
|
|||
return $this->get_model()->gets_for_type_and_user($id_user, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
*
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model(): \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Webhook($this->bdd);
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trigger a webhook and transmit the signal to webhook daemon if needed.
|
||||
* @param int $id_user : User to trigger the webhook for
|
||||
* @param string $type : Type of webhook to trigger
|
||||
* @param array $sms : The sms [
|
||||
* int 'id' => SMS id,
|
||||
* string 'at' => SMS date,
|
||||
* string 'text' => sms body,
|
||||
* string 'origin' => sms origin (number or phone id)
|
||||
* string 'destination' => sms destination (number or phone id)
|
||||
* ]
|
||||
*
|
||||
* @param int $id_user : User to trigger the webhook for
|
||||
* @param string $type : Type of webhook to trigger
|
||||
* @param array $sms : The sms [
|
||||
* int 'id' => SMS id,
|
||||
* string 'at' => SMS date,
|
||||
* string 'text' => sms body,
|
||||
* string 'origin' => sms origin (number or phone id)
|
||||
* string 'destination' => sms destination (number or phone id)
|
||||
* ]
|
||||
*
|
||||
* @return bool : False if no trigger, true else
|
||||
*/
|
||||
public function trigger (int $id_user, string $type, array $sms)
|
||||
public function trigger(int $id_user, string $type, array $sms)
|
||||
{
|
||||
$internal_setting = new Setting($this->bdd);
|
||||
$settings = $internal_setting->gets_for_user($id_user);
|
||||
|
@ -141,7 +130,20 @@ class Webhook extends StandardController
|
|||
$error_code = null;
|
||||
$queue = msg_get_queue(QUEUE_ID_WEBHOOK);
|
||||
$success = msg_send($queue, QUEUE_TYPE_WEBHOOK, $message, true, true, $error_code);
|
||||
|
||||
return (bool) $success;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
*
|
||||
* @return \descartes\Model
|
||||
*/
|
||||
protected function get_model(): \descartes\Model
|
||||
{
|
||||
$this->model = $this->model ?? new \models\Webhook($this->bdd);
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,8 +90,8 @@ namespace controllers\publics;
|
|||
|
||||
exit(self::ERROR_CODES['INVALID_CREDENTIALS']);
|
||||
}
|
||||
|
||||
if ($this->user['status'] !== \models\User::STATUS_ACTIVE)
|
||||
|
||||
if (\models\User::STATUS_ACTIVE !== $this->user['status'])
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['SUSPENDED_USER'];
|
||||
|
@ -121,6 +121,7 @@ namespace controllers\publics;
|
|||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'entry_type must be one of : ' . implode(', ', $entry_types) . '.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -165,6 +166,7 @@ namespace controllers\publics;
|
|||
}
|
||||
|
||||
$this->auto_http_code(true);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -182,7 +184,7 @@ namespace controllers\publics;
|
|||
*
|
||||
* @return : Id of scheduled created
|
||||
*/
|
||||
public function post_scheduled ()
|
||||
public function post_scheduled()
|
||||
{
|
||||
$at = $_POST['at'] ?? false;
|
||||
$text = $_POST['text'] ?? false;
|
||||
|
@ -193,10 +195,10 @@ namespace controllers\publics;
|
|||
$groups = $_POST['groups'] ?? [];
|
||||
$conditional_groups = $_POST['conditional_groups'] ?? [];
|
||||
|
||||
$numbers = is_array($numbers) ? $numbers : [$numbers];
|
||||
$contacts = is_array($contacts) ? $contacts : [$contacts];
|
||||
$groups = is_array($groups) ? $groups : [$groups];
|
||||
$conditional_groups = is_array($conditional_groups) ? $conditional_groups : [$conditional_groups];
|
||||
$numbers = \is_array($numbers) ? $numbers : [$numbers];
|
||||
$contacts = \is_array($contacts) ? $contacts : [$contacts];
|
||||
$groups = \is_array($groups) ? $groups : [$groups];
|
||||
$conditional_groups = \is_array($conditional_groups) ? $conditional_groups : [$conditional_groups];
|
||||
|
||||
if (!$at)
|
||||
{
|
||||
|
@ -209,6 +211,7 @@ namespace controllers\publics;
|
|||
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . ($at ? '' : 'at ') . ($text ? '' : 'text');
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -218,6 +221,7 @@ namespace controllers\publics;
|
|||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'at must be a date of format "Y-m-d H:i:s".';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -241,6 +245,7 @@ namespace controllers\publics;
|
|||
$return['error'] = self::ERROR_CODES['MISSING_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['MISSING_PARAMETER'] . 'You must specify at least one valid number, contact, group or conditional_group.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -250,6 +255,7 @@ namespace controllers\publics;
|
|||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'id_phone : You must specify an id_phone number among thoses of user phones.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -260,12 +266,14 @@ namespace controllers\publics;
|
|||
$return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
|
||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'];
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['response'] = $scheduled_id;
|
||||
$this->auto_http_code(true);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
|
@ -292,6 +300,7 @@ namespace controllers\publics;
|
|||
|
||||
$return['response'] = true;
|
||||
$this->auto_http_code(true);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,9 +114,10 @@ use Monolog\Logger;
|
|||
}
|
||||
|
||||
//Do not update if current status is delivered or failed
|
||||
if ($sended['status'] === \models\Sended::STATUS_DELIVERED || $sended['status'] === \models\Sended::STATUS_FAILED)
|
||||
if (\models\Sended::STATUS_DELIVERED === $sended['status'] || \models\Sended::STATUS_FAILED === $sended['status'])
|
||||
{
|
||||
$this->logger->info('Callback status update message ignore because status is already ' . $sended['status'] . '.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -125,18 +126,17 @@ use Monolog\Logger;
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function call on sms reception notification
|
||||
* We return nothing, and we let the adapter do his things.
|
||||
*
|
||||
* @param string $adapter_uid : Uid of the adapter to use
|
||||
* @param int $id_phone : Phone id
|
||||
* @param int $id_phone : Phone id
|
||||
*
|
||||
* @return bool : true on success, false on error
|
||||
*/
|
||||
public function reception (string $adapter_uid, int $id_phone)
|
||||
public function reception(string $adapter_uid, int $id_phone)
|
||||
{
|
||||
$this->logger->info('Callback reception call with adapter uid : ' . $adapter_uid);
|
||||
|
||||
|
@ -171,6 +171,7 @@ use Monolog\Logger;
|
|||
if ($response['error'])
|
||||
{
|
||||
$this->logger->error('Callback reception with adapter ' . $adapter_uid . ' failed : ' . $response['error_message']);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -180,10 +181,12 @@ use Monolog\Logger;
|
|||
if ($response['error'])
|
||||
{
|
||||
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Callback reception successfully received message : ' . json_encode($sms));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Connect', 'login'));
|
||||
}
|
||||
|
||||
if ($user['status'] !== \models\User::STATUS_ACTIVE)
|
||||
if (\models\User::STATUS_ACTIVE !== $user['status'])
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Votre compte est actuellement suspendu.');
|
||||
|
||||
|
@ -119,7 +119,7 @@ namespace controllers\publics;
|
|||
$token = $Tokenista->generate(3600, ['id_user' => $user['id']]);
|
||||
|
||||
$reset_link = \descartes\Router::url('Connect', 'reset_password', ['id_user' => $user['id'], 'token' => $token]);
|
||||
|
||||
|
||||
$mailer = new \controllers\internals\Mailer();
|
||||
$email_send = $mailer->enqueue($email, EMAIL_RESET_PASSWORD, ['reset_link' => $reset_link]);
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
$msg = ($result == 1 ? '1' : 'Pas de') . ' nouveau contact inséré.';
|
||||
$msg = (1 === $result ? '1' : 'Pas de') . ' nouveau contact inséré.';
|
||||
if ($result > 1)
|
||||
{
|
||||
$msg = $result . ' nouveaux contacts ont été insérés.';
|
||||
|
|
|
@ -52,6 +52,7 @@ class Phone extends \descartes\Controller
|
|||
if (!$adapter)
|
||||
{
|
||||
$phone['adapter'] = 'Inconnu';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ class Phone extends \descartes\Controller
|
|||
* Create a new phone.
|
||||
*
|
||||
* @param $csrf : CSRF token
|
||||
* @param string $_POST['name'] : Phone name
|
||||
* @param string $_POST['name'] : Phone name
|
||||
* @param string $_POST['adapter'] : Phone adapter
|
||||
* @param array $_POST['adapter_datas'] : Phone adapter datas
|
||||
*/
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace controllers\publics;
|
|||
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
|
||||
}
|
||||
|
||||
if ($received['id_phone'] !== null)
|
||||
if (null !== $received['id_phone'])
|
||||
{
|
||||
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
|
||||
if ($phone)
|
||||
|
@ -80,7 +80,7 @@ namespace controllers\publics;
|
|||
{
|
||||
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
|
||||
|
||||
if ($received['id_phone'] !== null)
|
||||
if (null !== $received['id_phone'])
|
||||
{
|
||||
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
|
||||
if ($phone)
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace controllers\publics;
|
|||
|
||||
foreach ($sendeds as $key => $sended)
|
||||
{
|
||||
if ($sended['id_phone'] !== null)
|
||||
if (null !== $sended['id_phone'])
|
||||
{
|
||||
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $sended['id_phone']);
|
||||
if ($phone)
|
||||
|
|
|
@ -45,18 +45,17 @@ class User extends \descartes\Controller
|
|||
$users = $this->internal_user->list();
|
||||
$this->render('user/list', ['users' => $users]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update status of users
|
||||
* Update status of users.
|
||||
*
|
||||
* @param array int $_GET['ids'] : User ids
|
||||
* @param mixed $csrf
|
||||
* @param int $status : 1 -> active, 0 -> suspended
|
||||
* @param int $status : 1 -> active, 0 -> suspended
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function update_status ($csrf, int $status)
|
||||
public function update_status($csrf, int $status)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
|
@ -65,7 +64,7 @@ class User extends \descartes\Controller
|
|||
return $this->redirect(\descartes\Router::url('User', 'list'));
|
||||
}
|
||||
|
||||
if ($status == 0)
|
||||
if (0 === $status)
|
||||
{
|
||||
$status = \models\User::STATUS_SUSPENDED;
|
||||
}
|
||||
|
@ -83,7 +82,6 @@ class User extends \descartes\Controller
|
|||
return $this->redirect(\descartes\Router::url('User', 'list'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cette fonction va supprimer une liste de users.
|
||||
*
|
||||
|
|
|
@ -50,7 +50,7 @@ class Launcher extends AbstractDaemon
|
|||
$this->start_sender_daemon();
|
||||
|
||||
$this->start_webhook_daemon();
|
||||
|
||||
|
||||
$this->start_mailer_daemon();
|
||||
|
||||
$phones = $this->internal_phone->get_all();
|
||||
|
@ -76,8 +76,7 @@ class Launcher extends AbstractDaemon
|
|||
$pid = null;
|
||||
exec('php ' . PWD . '/console.php controllers/internals/Console.php sender > /dev/null 2>&1 &');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function to start mailer daemon.
|
||||
*/
|
||||
|
|
|
@ -60,6 +60,7 @@ class Mailer extends AbstractDaemon
|
|||
{
|
||||
$this->logger->critical('Error for mailer queue reading, error code : ' . $error_code);
|
||||
$find_message = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,7 @@ class Mailer extends AbstractDaemon
|
|||
if (!$success)
|
||||
{
|
||||
$this->logger->error('Failed sending email');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ class Phone extends AbstractDaemon
|
|||
private function send_smss()
|
||||
{
|
||||
$internal_sended = new \controllers\internals\Sended($this->bdd);
|
||||
|
||||
|
||||
$find_message = true;
|
||||
while ($find_message)
|
||||
{
|
||||
|
@ -135,17 +135,17 @@ class Phone extends AbstractDaemon
|
|||
//Update last message time
|
||||
$this->last_message_at = microtime(true);
|
||||
|
||||
|
||||
//Do message sending
|
||||
//Do message sending
|
||||
$this->logger->info('Try send message : ' . json_encode($message));
|
||||
|
||||
|
||||
$response = $internal_sended->send($this->adapter, $this->phone['id_user'], $this->phone['id'], $message['text'], $message['destination'], $message['flash']);
|
||||
if ($response['error'])
|
||||
{
|
||||
$this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$this->logger->info('Successfully send message : ' . json_encode($message));
|
||||
}
|
||||
}
|
||||
|
@ -161,12 +161,13 @@ class Phone extends AbstractDaemon
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$response = $this->adapter->read();
|
||||
|
||||
if ($response['error'])
|
||||
{
|
||||
$this->logger->info('Error reading received smss : ' . $response['error_message']);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -180,15 +181,15 @@ class Phone extends AbstractDaemon
|
|||
{
|
||||
$this->logger->info('Receive message : ' . json_encode($sms));
|
||||
$response = $internal_received->receive($this->phone['id_user'], $this->phone['id'], $sms['text'], $sms['origin']);
|
||||
|
||||
|
||||
if ($response['error'])
|
||||
{
|
||||
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->logger->info('Message received successfully.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ class Webhook extends AbstractDaemon
|
|||
{
|
||||
$this->logger->critical('Error for webhook queue reading, error code : ' . $error_code);
|
||||
$find_message = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace models;
|
|||
* Return a phone by his name and user.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param string $name : phone name
|
||||
* @param string $name : phone name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
@ -44,7 +44,6 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count number of unread received sms for user.
|
||||
*
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace models;
|
|||
/**
|
||||
* Return sended for an uid and an adapter.
|
||||
*
|
||||
* @param int $id_user : Id of the user
|
||||
* @param int $id_user : Id of the user
|
||||
* @param string $uid : Uid of the sended
|
||||
* @param string $adapter : Adapter used to send the message
|
||||
*
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace models;
|
|||
const TYPE_SEND = 'send_sms';
|
||||
const TYPE_RECEIVE = 'receive_sms';
|
||||
|
||||
|
||||
/**
|
||||
* Find all webhooks for a user and for a type of webhook.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
function help ()
|
||||
function help()
|
||||
{
|
||||
echo 'Usage : ' . __FILE__ . ' <arg>' . "\n" .
|
||||
'Args :' . "\n" .
|
||||
|
@ -15,52 +15,51 @@
|
|||
$lint_commands = [
|
||||
'php ' . __DIR__ . '/php-cs-fixer.phar -v --dry-run --config="' . __DIR__ . '/php_cs.config" fix',
|
||||
];
|
||||
|
||||
|
||||
$fix_commands = [
|
||||
'php ' . __DIR__ . '/php-cs-fixer.phar --config="' . __DIR__ . '/php_cs.config" fix',
|
||||
];
|
||||
|
||||
|
||||
if (count($argv) < 2 || $argv[1] === 'help')
|
||||
if (count($argv) < 2 || 'help' === $argv[1])
|
||||
{
|
||||
help();
|
||||
}
|
||||
|
||||
if ($argv[1] === 'lint')
|
||||
if ('lint' === $argv[1])
|
||||
{
|
||||
echo "######################" . "\n";
|
||||
echo "# SHOW ERRORS TO FIX #" . "\n";
|
||||
echo "######################" . "\n";
|
||||
echo '######################' . "\n";
|
||||
echo '# SHOW ERRORS TO FIX #' . "\n";
|
||||
echo '######################' . "\n";
|
||||
echo "\n";
|
||||
|
||||
foreach ($lint_commands as $lint_command)
|
||||
{
|
||||
echo "Run : " . $lint_command . " \n";
|
||||
echo 'Run : ' . $lint_command . " \n";
|
||||
$return = shell_exec($lint_command);
|
||||
echo $return;
|
||||
echo "\n\n";
|
||||
}
|
||||
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ($argv[1] === 'fix')
|
||||
if ('fix' === $argv[1])
|
||||
{
|
||||
echo "##############" . "\n";
|
||||
echo "# FIX ERRORS #" . "\n";
|
||||
echo "##############" . "\n";
|
||||
echo '##############' . "\n";
|
||||
echo '# FIX ERRORS #' . "\n";
|
||||
echo '##############' . "\n";
|
||||
echo "\n";
|
||||
|
||||
|
||||
foreach ($fix_commands as $fix_command)
|
||||
{
|
||||
echo "Run : " . $fix_command . " \n";
|
||||
echo 'Run : ' . $fix_command . " \n";
|
||||
$return = shell_exec($fix_command);
|
||||
echo $return;
|
||||
echo "\n\n";
|
||||
}
|
||||
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
echo "Invalid arg : " . $argv[1] . "\n";
|
||||
echo 'Invalid arg : ' . $argv[1] . "\n";
|
||||
help();
|
||||
|
|
Loading…
Reference in New Issue