|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Fcm\Resources; |
|
4
|
|
|
|
|
5
|
|
|
class WebpushConfig implements FcmResource |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var array|null |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $headers; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var array|null |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $data; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array|null |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $notification; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var WebpushFcmOptions|null |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $fcmOptions; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return static |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function create(): self |
|
31
|
|
|
{ |
|
32
|
|
|
return new self; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return array|null |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getHeaders(): ?array |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->headers; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param array|null $headers |
|
45
|
|
|
* @return WebpushConfig |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setHeaders(?array $headers): self |
|
48
|
|
|
{ |
|
49
|
|
|
$this->headers = $headers; |
|
50
|
|
|
|
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return array|null |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getData(): ?array |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->data; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param array|null $data |
|
64
|
|
|
* @return WebpushConfig |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setData(?array $data): self |
|
67
|
|
|
{ |
|
68
|
|
|
$this->data = $data; |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return array|null |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getNotification(): ?array |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->notification; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param array|null $notification |
|
83
|
|
|
* @return WebpushConfig |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setNotification(?array $notification): self |
|
86
|
|
|
{ |
|
87
|
|
|
$this->notification = $notification; |
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return WebpushFcmOptions|null |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getFcmOptions(): ?WebpushFcmOptions |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->fcmOptions; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param WebpushFcmOptions|null $fcmOptions |
|
102
|
|
|
* @return WebpushConfig |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setFcmOptions(?WebpushFcmOptions $fcmOptions): self |
|
105
|
|
|
{ |
|
106
|
|
|
$this->fcmOptions = $fcmOptions; |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritdoc} |
|
113
|
|
|
*/ |
|
114
|
|
|
public function toArray(): array |
|
115
|
|
|
{ |
|
116
|
|
|
return [ |
|
117
|
|
|
'headers' => $this->getHeaders(), |
|
118
|
|
|
'data' => $this->getData(), |
|
119
|
|
|
'notification' => $this->getNotification(), |
|
120
|
|
|
'fcm_options' => ! is_null($this->getFcmOptions()) ? $this->getFcmOptions()->toArray() : null, |
|
121
|
|
|
]; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|