mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-12 06:52:12 +09:00
Improve error handling
This commit is contained in:
parent
50e3dc4574
commit
a92c77655f
5 changed files with 26 additions and 11 deletions
|
|
@ -99,9 +99,10 @@ abstract class Base implements \Rhymix\Framework\Drivers\SMSInterface
|
|||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param array $messages
|
||||
* @param object $original
|
||||
* @return bool
|
||||
*/
|
||||
public function send(array $messages)
|
||||
public function send(array $messages, \Rhymix\Framework\SMS $original)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,9 +43,10 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
|||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param array $messages
|
||||
* @param object $original
|
||||
* @return bool
|
||||
*/
|
||||
public function send(array $messages)
|
||||
public function send(array $messages, \Rhymix\Framework\SMS $original)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -58,7 +59,7 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
|||
$options->type = $message->type;
|
||||
$options->from = $message->from;
|
||||
$options->to = implode(',', $message->to);
|
||||
$options->text = $message->content ?: 'SMS';
|
||||
$options->text = $message->content ?: $message->type;
|
||||
$options->charset = 'utf8';
|
||||
if ($message->delay && $message->delay > time())
|
||||
{
|
||||
|
|
@ -81,7 +82,7 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
|||
if (!$result->success_count)
|
||||
{
|
||||
$error_codes = implode(', ', $result->error_list ?: array('Unknown'));
|
||||
$message->errors[] = 'Error (' . $error_codes . ') while sending message ' . $i . ' of ' . count($messages) . ' to ' . $options->to;
|
||||
$original->addError('Error (' . $error_codes . ') while sending message ' . ($i + 1) . ' of ' . count($messages) . ' to ' . $options->to);
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,10 @@ class Dummy extends Base implements \Rhymix\Framework\Drivers\SMSInterface
|
|||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param array $messages
|
||||
* @param object $original
|
||||
* @return bool
|
||||
*/
|
||||
public function send(array $messages)
|
||||
public function send(array $messages, \Rhymix\Framework\SMS $original)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ interface SMSInterface
|
|||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param array $messages
|
||||
* @param object $original
|
||||
* @return bool
|
||||
*/
|
||||
public function send(array $messages);
|
||||
public function send(array $messages, \Rhymix\Framework\SMS $original);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class SMS
|
|||
* Instance properties.
|
||||
*/
|
||||
public $driver = null;
|
||||
public $caller = '';
|
||||
protected $caller = '';
|
||||
protected $from = '';
|
||||
protected $to = array();
|
||||
protected $subject = '';
|
||||
|
|
@ -21,7 +21,7 @@ class SMS
|
|||
protected $force_sms = false;
|
||||
protected $allow_split_sms = true;
|
||||
protected $allow_split_lms = true;
|
||||
public $errors = array();
|
||||
protected $errors = array();
|
||||
protected $sent = false;
|
||||
|
||||
/**
|
||||
|
|
@ -474,7 +474,7 @@ class SMS
|
|||
$messages = $this->_formatSpec($this->driver->getAPISpec());
|
||||
if (count($messages))
|
||||
{
|
||||
$this->sent = $this->driver->send($messages) ? true : false;
|
||||
$this->sent = $this->driver->send($messages, $this) ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -533,6 +533,17 @@ class SMS
|
|||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error message.
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public function addError($message)
|
||||
{
|
||||
$this->errors[] = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the current message according to an API spec.
|
||||
*
|
||||
|
|
@ -574,7 +585,6 @@ class SMS
|
|||
$subject = $this->getSubject();
|
||||
$content = $this->getContent();
|
||||
$attachments = $attachments = $this->getAttachments();
|
||||
$last_content = 'MMS';
|
||||
|
||||
// Determine the message type.
|
||||
if (!$this->isForceSMS() && ($spec['lms_supported'] || $spec['mms_supported']))
|
||||
|
|
@ -654,6 +664,7 @@ class SMS
|
|||
|
||||
// Generate a message for each part of the content and attachments.
|
||||
$message_count = max(count($content_parts), count($attachments));
|
||||
$last_content = $item->type;
|
||||
for ($i = 1; $i <= $message_count; $i++)
|
||||
{
|
||||
// Get the message content.
|
||||
|
|
@ -663,7 +674,7 @@ class SMS
|
|||
}
|
||||
else
|
||||
{
|
||||
$item->content = $last_content ?: 'MMS';
|
||||
$item->content = $last_content ?: $item->type;
|
||||
}
|
||||
|
||||
// Get the attachment.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue