Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 40bc6bd

Browse files
committed
fix: ( #3 ) Fix set alert type of array is not support
1 parent 98d5fa4 commit 40bc6bd

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/Message.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Message implements Contracts\PushPayloadMakeable
1212

1313
/**
1414
* Simple alert.
15-
* @var string
15+
* @var string|array
1616
*/
1717
protected $alert;
1818

@@ -36,24 +36,27 @@ class Message implements Contracts\PushPayloadMakeable
3636

3737
/**
3838
* Create a push message.
39-
* @param null|string $alert
39+
* @param null|string|array $alert
4040
*/
41-
public function __construct(?string $alert = null)
41+
public function __construct($alert = null)
4242
{
43-
if (is_string($alert)) {
43+
if (is_string($alert) || is_array($alert)) {
4444
$this->setAlert($alert);
4545
}
4646
}
4747

4848
/**
4949
* Set simple alert.
50-
* @param string $alert
50+
* @param string|array $alert
5151
*/
5252
public function setAlert(string $alert)
5353
{
54-
$this->alert = $alert;
54+
if (is_string($alert) || is_array($alert)) {
55+
$this->alert = $alert;
56+
return $this;
57+
}
5558

56-
return $this;
59+
throw new \Exception('Alert 只允许字符串或者数组');
5760
}
5861

5962
/**
@@ -72,11 +75,15 @@ public function setMessage(?string $contents = null, array $options) {
7275
/**
7376
* Set notifications.
7477
* @param string $platform static::<IOS|ANDROID|WP>
75-
* @param string $alert
78+
* @param string|array $alert
7679
* @param array $options
7780
*/
78-
public function setNotification(string $platform, string $alert, array $options = [])
81+
public function setNotification(string $platform, $alert, array $options = [])
7982
{
83+
if (!is_array($alert) || !is_array($alert)) {
84+
throw new \Exception('Alert 只允许字符串或者数组');
85+
}
86+
8087
$this->notifications[$platform] = [
8188
'alert' => $alert,
8289
'options' => $options,

0 commit comments

Comments
 (0)