-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.php
More file actions
155 lines (132 loc) · 2.78 KB
/
Copy pathAction.php
File metadata and controls
155 lines (132 loc) · 2.78 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
declare(strict_types=1);
namespace Crustum\Notification\Message;
use Cake\Routing\Router;
/**
* Notification Action
*
* Fluent builder for notification action buttons.
*
* @phpstan-consistent-constructor
*/
class Action
{
/**
* Action name/identifier
*
* @var string
*/
protected string $name;
/**
* Action label (button text)
*
* @var string|null
*/
protected ?string $label = null;
/**
* Action URL
*
* @var array<string, mixed>|string|null
*/
protected string|array|null $url = null;
/**
* Action type/color
*
* @var string|null
*/
protected ?string $type = null;
/**
* Icon identifier
*
* @var string|null
*/
protected ?string $icon = null;
/**
* Constructor
*
* @param string $name Action identifier
*/
public function __construct(string $name)
{
$this->name = $name;
}
/**
* Create a new action instance
*
* @param string $name Action identifier
* @return static
* @phpstan-return static
*/
public static function new(string $name): static
{
return new static($name);
}
/**
* Set the action label
*
* @param string $label Button text
* @return static
*/
public function label(string $label): static
{
$this->label = $label;
return $this;
}
/**
* Set the action URL
*
* @param array<string, mixed>|string $url Target URL or routing array
* @return static
*/
public function url(/sitelet?url=https%3A%2F%2Fgithub.com%2FCrustum%2FNotification%2Fblob%2Fmain%2Fsrc%2FMessage%2Fstring%7Carray%2520%24url): static
{
$this->url = $url;
return $this;
}
/**
* Set the action type/color
*
* @param string $type Action type (primary, success, danger, etc.)
* @return static
*/
public function type(string $type): static
{
$this->type = $type;
return $this;
}
/**
* Set the action icon
*
* @param string $icon Icon identifier
* @return static
*/
public function icon(string $icon): static
{
$this->icon = $icon;
return $this;
}
/**
* Convert action to array
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$data = [
'name' => $this->name,
];
if ($this->label !== null) {
$data['label'] = $this->label;
}
if ($this->url !== null) {
$data['url'] = is_array($this->url) ? Router::url(/sitelet?url=https%3A%2F%2Fgithub.com%2FCrustum%2FNotification%2Fblob%2Fmain%2Fsrc%2FMessage%2F%24this-%26gt%3Burl%2C%2520true) : $this->url;
}
if ($this->type !== null) {
$data['type'] = $this->type;
}
if ($this->icon !== null) {
$data['icon'] = $this->icon;
}
return $data;
}
}