forked from shuvroroy/nova-dynamic-views
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomComponents.php
45 lines (34 loc) · 885 Bytes
/
CustomComponents.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
<?php
namespace ShuvroRoy\NovaDynamicViews;
class CustomComponents implements \JsonSerializable
{
protected string $class;
protected array $items = [];
public static function make(string $class = ''): static
{
$obj = new static();
$obj->class = $class;
return $obj;
}
public function addItem(string $name, array $meta = []): static
{
$item = ['name'=> $name];
if($meta) {
$item['meta'] = $meta;
}
$this->items[] = $item;
return $this;
}
public function setClass(string $class): static
{
$this->class = $class;
return $this;
}
public function jsonSerialize(): array
{
return array_filter([
'class' => $this->class,
'items' => $this->items
]);
}
}