/
index.php
38 lines (29 loc) · 1.17 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
* This is a client that will implement the SMSFactory
* You can pass in 'Twilio' or whatever service to it and it will create that service
* Then you can call sendMessage() to send the message with the params (fromNumber, toNumber, message)
* sendMessage is required because of the contract with the concrete class of Twilio and its dependance on
* SMSAbstract.php
*
* The intent is to be used in a larger program that has more SMS services to pick from, to get away from crazy
* conditionals, and to have maintainable, reusable code.
*
* Thanh
*/
require_once __DIR__ . '/vendor/autoload.php';
//pass phone number here
$toPhoneNumber = '';
$messageBody = "Hi mate, testing from Twilio! \n\n ok?";
//if there was a different service, you can use it (or if fail, use fallback)
try {
$SMSObj = \App\Library\SMSFactory::create('Twilio');
} catch (Exception $e) {
\App\Helper\HTTPResponse::response(400, $e->getMessage());
}
//try to send the message using the service created in the factory
try {
$SMSObj->sendMessage(FROM_PHONE_NUMBER, $toPhoneNumber, $messageBody);
} catch (Exception $e) {
\App\Helper\HTTPResponse::response(400, $e->getMessage());
}