forked from filipajdacic/yii2-twilio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YiiTwilio.php
75 lines (59 loc) · 1.57 KB
/
YiiTwilio.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace openecommerce\yiitwilio;
use yii\base\Component;
use \Services_Twilio;
/**
* YiiTwilio class
* @author Filip Ajdacic <[email protected]>
* @license MIT
* @version 1.0
* @copyright (C) 2016 Filip Ajdacic <[email protected]>
* @see http://github.com/filipajdacic
* */
class YiiTwilio extends Component
{
/**
* The internal Twilio object.
*
* @var object Twilio
*/
private $twilioClass;
/**
** @var string $account_sid -> Twilio Account ID
*/
public $account_sid;
/**
** @var string $auth_key -> Twilio Authorization Key
*/
public $auth_key;
/**
* init() called by yii.
*/
public function init()
{
try {
$this->twilioClass = new Services_Twilio($this->account_sid, $this->auth_key);
} catch (Exception $e) {
throw $e;
}
}
public function initTwilio() {
return $this->twilioClass;
}
/**
* Use magic PHP function __call to route function calls to the Twilio class.
* Look into the Twilio class for possible functions.
*
* @param string $methodName Method name from Twilio class
* @param array $methodParams Parameters pass to method
* @return mixed
*/
public function __call($methodName, $methodParams)
{
if (method_exists($this->twilioClass, $methodName)) {
return call_user_func_array(array($this->twilioClass, $methodName), $methodParams);
} else {
return parent::__call($methodName, $methodParams);
}
}
}