-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathAlert.php
94 lines (68 loc) · 1.86 KB
/
Alert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Native\Laravel;
use Native\Laravel\Client\Client;
class Alert
{
protected ?string $type = null;
protected ?string $title = null;
protected ?string $detail = null;
protected ?array $buttons = null;
protected ?int $defaultId = null;
protected ?int $cancelId = null;
final public function __construct(protected Client $client) {}
public static function new(): self
{
return new static(new Client);
}
public function type(string $type): self
{
$this->type = $type;
return $this;
}
public function title(string $title): self
{
$this->title = $title;
return $this;
}
public function detail(string $detail): self
{
$this->detail = $detail;
return $this;
}
public function buttons(array $buttons): self
{
$this->buttons = $buttons;
return $this;
}
public function defaultId(int $defaultId): self
{
$this->defaultId = $defaultId;
return $this;
}
public function cancelId(int $cancelId): self
{
$this->cancelId = $cancelId;
return $this;
}
public function show(string $message): int
{
$response = $this->client->post('alert/message', [
'message' => $message,
'type' => $this->type,
'title' => $this->title,
'detail' => $this->detail,
'buttons' => $this->buttons,
'defaultId' => $this->defaultId,
'cancelId' => $this->cancelId,
]);
return (int) $response->json('result');
}
public function error(string $title, string $message): bool
{
$response = $this->client->post('alert/error', [
'title' => $title,
'message' => $message,
]);
return (bool) $response->json('result');
}
}