1
|
|
|
<?php |
2
|
|
|
namespace ker0x\CakeGcm\Controller\Component; |
3
|
|
|
|
4
|
|
|
use Cake\Controller\Component; |
5
|
|
|
use ker0x\CakeGcm\Webservice\Gcm; |
6
|
|
|
use \Exception; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Gcm Component |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
class GcmComponent extends Component |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Gcm property |
17
|
|
|
* |
18
|
|
|
* @var object |
19
|
|
|
*/ |
20
|
|
|
protected $_gcm = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Initialize config data and properties. |
24
|
|
|
* |
25
|
|
|
* @param array $config Array of configuration settings |
26
|
|
|
*/ |
27
|
|
|
public function initialize(array $config= []) |
28
|
|
|
{ |
29
|
|
|
parent::initialize($config); |
30
|
|
|
$this->_gcm = new Gcm($config); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Send a downstream message to one or more devices |
35
|
|
|
* |
36
|
|
|
* @param mixed $ids Devices'ids |
37
|
|
|
* @param array $payload The notification and/or some datas |
38
|
|
|
* @param array $parameters Parameters for the GCM request |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
|
|
public function send($ids = null, array $payload = [], array $parameters = []) |
42
|
|
|
{ |
43
|
|
|
return $this->_gcm->send($ids, $payload, $parameters); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Shortcut to send notification |
48
|
|
|
* |
49
|
|
|
* @param mixed $ids Devices'ids |
50
|
|
|
* @param array $notification The notification |
51
|
|
|
* @param array $parameters Parameters for the GCM request |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
|
|
public function sendNotification($ids = null, array $notification = [], array $parameters = []) |
55
|
|
|
{ |
56
|
|
|
return $this->_gcm->sendNotification($ids, $notification, $parameters); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Shortcut to send datas |
61
|
|
|
* |
62
|
|
|
* @param mixed $ids Devices'ids |
63
|
|
|
* @param array $data Some datas |
64
|
|
|
* @param array $parameters Parameters for the GCM request |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
|
|
public function sendData($ids = null, array $data = [], array $parameters = []) |
68
|
|
|
{ |
69
|
|
|
return $this->_gcm->sendData($ids, $data, $parameters); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return the response of the push |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function response() |
78
|
|
|
{ |
79
|
|
|
return $this->_gcm->response(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|