-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMns.php
executable file
·46 lines (40 loc) · 1.06 KB
/
Mns.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
<?php
namespace xionglonghua\yii2mns;
use Yii;
use yii\base\Component;
use AliyunMNS\Client;
class Mns extends Component
{
public $accessId = '';
public $accessKey = '';
public $endpoint = '';
private $client = null;
private $queues = [];
public function init()
{
parent::init();
$this->client = new Client($this->endpoint, $this->accessId, $this->accessKey);
}
public function __call($method_name, $args)
{
if (method_exists($this->client, $method_name)) {
return call_user_func_array([$this->client, $method_name], $args);
} else {
return parent::__call($method_name, $args);
}
}
public function __get($name)
{
if (isset($this->queues[$name])) {
return $this->queues[$name];
}
$params = [
'class' => Queue::className(),
'client' => $this->client,
'name' => $name,
];
$queue = Yii::createObject($params);
$this->queues[$name] = $queue;
return $queue;
}
}