|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Thinktomorrow\Chief\Management\Details; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @property $key |
|
11
|
|
|
* @property $singular |
|
12
|
|
|
* @property $plural |
|
13
|
|
|
* @property $internal_label |
|
14
|
|
|
* @property $title |
|
15
|
|
|
* @property $subtitle |
|
16
|
|
|
* @property $intro |
|
17
|
|
|
*/ |
|
18
|
|
|
class Details implements Arrayable |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var array */ |
|
21
|
|
|
protected $values = []; |
|
22
|
|
|
|
|
23
|
110 |
|
public function __construct($id, string $key, string $singular, string $plural, string $internal_label, string $title) |
|
24
|
|
|
{ |
|
25
|
|
|
// Default model details |
|
26
|
110 |
|
$this->values['id'] = $id; |
|
27
|
110 |
|
$this->values['key'] = $key; |
|
28
|
110 |
|
$this->values['singular'] = $singular; |
|
29
|
110 |
|
$this->values['plural'] = $plural; |
|
30
|
110 |
|
$this->values['internal_label'] = $internal_label; |
|
31
|
110 |
|
$this->values['title'] = $title; |
|
32
|
110 |
|
} |
|
33
|
|
|
|
|
34
|
94 |
|
public function get($attribute = null) |
|
35
|
|
|
{ |
|
36
|
94 |
|
if (array_key_exists($attribute, $this->values)) { |
|
37
|
94 |
|
return $this->values[$attribute]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
return null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function has($attribute): bool |
|
44
|
|
|
{ |
|
45
|
|
|
return null !== $this->get($attribute); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
80 |
|
public function set($attribute, $value) |
|
49
|
|
|
{ |
|
50
|
80 |
|
$this->values[$attribute] = $value; |
|
51
|
|
|
|
|
52
|
80 |
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
94 |
|
public function __get($attribute) |
|
56
|
|
|
{ |
|
57
|
94 |
|
return $this->get($attribute); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function __set($attribute, $value) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->set($attribute, $value); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function __toString() |
|
66
|
|
|
{ |
|
67
|
|
|
return (string) $this->get('key'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the instance as an array. |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function toArray() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->values; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|