1 | <?php |
||
8 | class OneSignalMessage |
||
9 | { |
||
10 | use OneSignalHelpers; |
||
11 | |||
12 | /** @var array */ |
||
13 | protected $data = []; |
||
14 | |||
15 | /** @var array */ |
||
16 | protected $payload = []; |
||
17 | |||
18 | /** |
||
19 | * @param string $body |
||
20 | * |
||
21 | * @return static |
||
22 | */ |
||
23 | 1 | public static function create($body = '') |
|
24 | { |
||
25 | 1 | return new static($body); |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param string $body |
||
30 | */ |
||
31 | 20 | public function __construct($body = '') |
|
32 | { |
||
33 | 20 | $this->body($body); |
|
34 | 20 | } |
|
35 | |||
36 | /** |
||
37 | * Set the message body. |
||
38 | * |
||
39 | * @param string $value |
||
40 | * |
||
41 | * @return $this |
||
42 | */ |
||
43 | 20 | public function body($value) |
|
44 | { |
||
45 | 20 | if (is_array($value)) { |
|
46 | $this->setParameter('contents', $value); |
||
47 | } else { |
||
48 | 20 | $this->setParameter('contents', ['en' => $value]); |
|
49 | } |
||
50 | |||
51 | 20 | return $this; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Set the message subject. |
||
56 | * |
||
57 | * @param string $value |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | 6 | public function subject($value) |
|
62 | { |
||
63 | 6 | if (is_array($value)) { |
|
64 | $this->setParameter('headings', $value); |
||
65 | } else { |
||
66 | 6 | $this->setParameter('headings', ['en' => $value]); |
|
67 | } |
||
68 | |||
69 | 6 | return $this; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Set the message url. |
||
74 | * |
||
75 | * @param string $value |
||
76 | * |
||
77 | * @return $this |
||
78 | */ |
||
79 | 6 | public function url($value) |
|
83 | |||
84 | /** |
||
85 | * Set additional data. |
||
86 | * |
||
87 | * @param string $key |
||
88 | * @param mixed $value |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | 1 | public function setData(string $key, $value) |
|
96 | |||
97 | /** |
||
98 | * Set additional parameters. |
||
99 | * |
||
100 | * @param string $key |
||
101 | * @param mixed $value |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | 20 | public function setParameter(string $key, $value) |
|
111 | |||
112 | /** |
||
113 | * @return array |
||
114 | */ |
||
115 | 20 | public function toArray() |
|
119 | } |
||
120 |