Nothing found

You are viewing an older version of this page.

Open current version

Bulk SMS (PHP SDK 1.0)

The class BulkGate\Sms\BulkMessage represents the object, which connects `BulkGate\Sms\Message` type of messages to a bulk message (campaign).

use BulkGate\Sms\BulkMessage;

The constructor has one optional array type parameter that must contain `BulkGate\Sms\Message` items.

$array = [ new BulkGate\Sms\Message("447971700001", "test1"), new BulkGate\Sms\Message("447971700002", "test2"), new BulkGate\Sms\Message("447971700003", "test3"), new BulkGate\Sms\Message("447971700004", "test4"), ]; $bulk_message = new BulkMessage($array);

Messages can be added one at a time:

$message = new BulkGate\Sms\Message( new BulkGate\Sms\Message\PhoneNumber("7971700001", BulkGate\Sms\Country::UNITED_KINGDOM), new BulkGate\Sms\Message\Text("test<number>", [ 'number' => '5' ]) ); /** @var BulkGate\Sms\BulkMessage $bulk_message */ $bulk_message->addMessage(message);

Iterator

You can browse through messages using the foreach cycle

/** * @var BulkGate\Sms\BulkMessage $bulk_message * @var BulkGate\Sms\Message $message */ foreach($bulk_message as $message) { echo $message; }

You can find out the number of messages using count()

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $bulk_message->count();

JSON Support

The BulkGate\Sms\BulkMessage object implements the \JsonSerializable interface that lets you convert it via the json_encode() function to JSON format.

/** @var BulkGate\Sms\BulkMessage $bulk_message */ echo json_encode($bulk_message);

The output is:

[ { "number": { "number": "447971700001", "iso": null }, "text": "test1", "status": "preparation", "price": 0.0, "credit": 0.0, "id": null, "scheduled": null }, { "number": { "number": "447971700002", "iso": null }, "text": "test2", "status": "preparation", "price": 0.0, "credit": 0.0, "id": null, "scheduled": null }, { "number": { "number": "447971700003", "iso": null }, "text": "test3", "status": "preparation", "price": 0.0, "credit": 0.0, "id": null, "scheduled": null }, { "number": { "number": "447971700004", "iso": null }, "text": "test4", "status": "preparation", "price": 0.0, "credit": 0.0, "id": null, "scheduled": null }, { "number": { "number": "7971700005", "iso": "gb" }, "text": "test5", "status": "preparation", "price": 0.0, "credit": 0.0, "id": null, "scheduled": null } ]

Convert to string

The BulkGate\Sms\BulkMessage object implements the magic method __string().

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $message = (string) $bulk_message; // into the variable echo $bulk_message; // to the output

Output is:

447971700001: test1 447971700002: test2 447971700003: test3 447971700004: test4 797170000ř: test5

Convert to array

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $array = $message->toArray();
Was this page helpful?