Source for file SMS.php
Documentation is available at SMS.php
require_once 'Net/SMS/Exception.php';
* Copyright 2003-2009 The Horde Project (http://www.horde.org/)
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
* $Horde: framework/Net_SMS/SMS.php,v 1.25 2009/01/06 17:49:34 jan Exp $
* @author Marko Djukic <marko@oblo.com>
* A hash containing any parameters for the current gateway driver.
* @param array $params Any parameters needed for this gateway driver.
// Iterate over specified options, merging with defaults
foreach ($params as $key => $value) {
$this->_params[$key] = $value;
* Query the current Gateway object to find out if it supports the given
* @param string $capability The capability to test for.
* @return mixed Whether or not the capability is supported or any other
* value that the capability wishes to report.
if (!empty ($this->capabilities[$capability])) {
return $this->capabilities[$capability];
* Authenticates against the gateway if required.
* @return mixed True on success or PEAR Error on failure.
/* Do authentication for this gateway if driver requires it. */
$this->_auth = $this->_authenticate ();
* Sends a message to one or more recipients. Hands off the actual sending
* @param array $message The message to be sent, which is composed of:
* id - A unique ID for the message;
* to - An array of recipients;
* text - The text of the message;
* @return mixed True on success or PEAR Error on failure.
public function send($message)
throw new InvalidArgumentException ("Parameter message is expected to be an array/hash");
if (!isset ($message['id'])) {
throw new InvalidArgumentException ("Please specify message id, ie: array('id' => 1)");
if (!isset ($message['to'])) {
throw new InvalidArgumentException ("Please specify an array of recipients, ie: array('to' => array('phone1', 'phone2'))");
if (!isset ($message['text'])) {
throw new InvalidArgumentException ("Please specify message text, ie: array('text' => 'Hi!')");
/* Make sure the recipients are in an array. */
$message['to'] = array ($message['to']);
/* Array to store each send. */
/* If gateway supports batch sending, preference is given to this
/* Split up the recipients in the max recipients per batch as
* supported by gateway. */
$iMax = count($message['to']);
$batches = ceil($iMax / $max_per_batch);
/* Loop through the batches and compose messages to be sent. */
for ($b = 0; $b < $batches; $b++ ) {
$recipients = array_slice($message['to'], ($b * $max_per_batch), $max_per_batch);
$response = $this->_send($message, $recipients);
foreach ($recipients as $recipient) {
if (empty ($response[$recipient])) {
if ($response[$recipient][0 ] == 1 ) {
/* Message was sent, store remote id. */
$remote_id = $response[$recipient][1 ];
/* Message failed, store error code. */
$error = $response[$recipient][1 ];
$sends[] = array ('message_id' => $message['id'],
'remote_id' => $remote_id,
'recipient' => $recipient,
/* No batch sending available, just loop through all recipients
* and send a message for each one. */
foreach ($message['to'] as $recipient) {
$response = $this->_send($message, $recipient);
/* Message was sent, store remote id if any. */
$remote_id = (isset ($response[1 ]) ? $response[1 ] : null );
/* Message failed, store error code. */
$sends[] = array ('message_id' => $message['id'],
'remote_id' => $remote_id,
'recipient' => $recipient,
* If the current driver has a credit capability, queries the gateway for
* a credit balance and returns the value.
* @return integer Value indicating available credit or null if not
return $this->_getBalance ();
* This function does the actual sending of the message.
* @param array $message The array containing the message and its send
* @param array $to The recipients.
* @return array An array with the success status and additional
protected function _send($message, $to) {
* Returns a string representation of an error code.
* @param integer $error The error code to look up.
* @param string $text An existing error text to use to raise a
* @return mixed A textual message corresponding to the error code or a
* PEAR Error if passed an existing error text.
* @todo Check which of these are actually required and trim down the
public function getError($error, $error_text = '')
Documentation generated on Mon, 11 Mar 2019 15:57:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|