1 | <?php |
||
14 | class OneSignalMessage |
||
15 | { |
||
16 | use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers, SilentHelpers, Deprecated; |
||
17 | |||
18 | /** @var array */ |
||
19 | protected $payload = []; |
||
20 | |||
21 | /** |
||
22 | * @param string $body |
||
23 | * |
||
24 | * @return static |
||
25 | */ |
||
26 | 1 | public static function create($body = '') |
|
27 | { |
||
28 | 1 | return new static($body); |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param string $body |
||
33 | */ |
||
34 | 25 | public function __construct($body = '') |
|
35 | { |
||
36 | 25 | $this->setBody($body); |
|
37 | 25 | } |
|
38 | |||
39 | /** |
||
40 | * Set the message body. |
||
41 | * |
||
42 | * @param mixed $value |
||
43 | * |
||
44 | * @return $this |
||
45 | */ |
||
46 | 25 | public function setBody($value) |
|
47 | { |
||
48 | 25 | return $this->setParameter('contents', $this->parseValueToArray($value)); |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Set the message subject. |
||
53 | * |
||
54 | * @param mixed $value |
||
55 | * |
||
56 | * @return $this |
||
57 | */ |
||
58 | 1 | public function setSubject($value) |
|
62 | |||
63 | /** |
||
64 | * Set the message template_id. |
||
65 | * |
||
66 | * @param string $value |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setTemplate($value) |
||
71 | { |
||
72 | Arr::forget($this->payload, 'contents'); |
||
73 | |||
74 | return $this->setParameter('template_id', $value); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param mixed $value |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | 25 | protected function parseValueToArray($value) |
|
86 | |||
87 | /** |
||
88 | * Set additional data. |
||
89 | * |
||
90 | * @param string $key |
||
91 | * @param mixed $value |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | 1 | public function setData(string $key, $value) |
|
99 | |||
100 | /** |
||
101 | * Set parameters. |
||
102 | * |
||
103 | * @param string $key |
||
104 | * @param mixed $value |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | 25 | public function setParameter(string $key, $value) |
|
114 | |||
115 | /** |
||
116 | * Get parameters. |
||
117 | * |
||
118 | * @param string $key |
||
119 | * @param mixed $default |
||
120 | * |
||
121 | * @return mixed |
||
122 | */ |
||
123 | 3 | public function getParameter(string $key, $default = null) |
|
127 | |||
128 | /** |
||
129 | * @return array |
||
130 | */ |
||
131 | 25 | public function toArray() |
|
135 | } |
||
136 |