1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Push notification services abstraction (http://github.com/juliangut/tify) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/juliangut/tify for the canonical source repository |
6
|
|
|
* |
7
|
|
|
* @license https://github.com/juliangut/tify/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Jgut\Tify\Notification; |
11
|
|
|
|
12
|
|
|
use Jgut\Tify\Service\AbstractService; |
13
|
|
|
use Jgut\Tify\Service\Gcm as GcmService; |
14
|
|
|
use Jgut\Tify\Recipient\AbstractRecipient; |
15
|
|
|
use Jgut\Tify\Recipient\Gcm as GcmRecipient; |
16
|
|
|
use Jgut\Tify\Message\AbstractMessage; |
17
|
|
|
use Jgut\Tify\Message\Gcm as GcmMessage; |
18
|
|
|
|
19
|
|
|
class Gcm extends AbstractNotification |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
protected $defaultOptions = [ |
25
|
|
|
'collapse_key' => null, |
26
|
|
|
'delay_while_idle' => null, |
27
|
|
|
'time_to_live' => null, |
28
|
|
|
'restricted_package_name' => null, |
29
|
|
|
'dry_run' => null, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param \Jgut\Tify\Service\Gcm $service |
34
|
|
|
* @param \Jgut\Tify\Message\Gcm $message |
35
|
|
|
* @param \Jgut\Tify\Recipient\Gcm[] $recipients |
36
|
|
|
* @param array $options |
37
|
|
|
*/ |
38
|
|
|
public function __construct(GcmService $service, GcmMessage $message, array $recipients = [], array $options = []) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($service, $message, $recipients, $options); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
* |
46
|
|
|
* @throws \InvalidArgumentException |
47
|
|
|
*/ |
48
|
|
|
public function setService(AbstractService $service) |
49
|
|
|
{ |
50
|
|
|
if (!$service instanceof GcmService) { |
51
|
|
|
throw new \InvalidArgumentException('Service must be an accepted GCM service'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->service = $service; |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
* |
62
|
|
|
* @throws \InvalidArgumentException |
63
|
|
|
*/ |
64
|
|
|
public function setMessage(AbstractMessage $message) |
65
|
|
|
{ |
66
|
|
|
if (!$message instanceof GcmMessage) { |
67
|
|
|
throw new \InvalidArgumentException('Message must be an accepted GCM message'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->message = $message; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
* |
78
|
|
|
* @throws \InvalidArgumentException |
79
|
|
|
*/ |
80
|
|
|
public function addRecipient(AbstractRecipient $recipient) |
81
|
|
|
{ |
82
|
|
|
if (!$recipient instanceof GcmRecipient) { |
83
|
|
|
throw new \InvalidArgumentException('Recipient must be an accepted GCM recipient'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->recipients[] = $recipient; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|