1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Support\Exposer; |
13
|
|
|
|
14
|
|
|
class Builder implements BuilderInterface |
15
|
|
|
{ |
16
|
|
|
private $value; |
17
|
|
|
|
18
|
|
|
private $parent; |
19
|
|
|
|
20
|
|
|
private ?array $columns = null; |
21
|
|
|
|
22
|
|
|
private ?string $field = null; |
23
|
|
|
|
24
|
|
|
private ?string $key = null; |
25
|
|
|
|
26
|
|
|
private ?string $contextKey = null; |
27
|
|
|
|
28
|
|
|
private bool $expose = true; |
29
|
|
|
|
30
|
|
|
private bool $protected = false; |
31
|
|
|
|
32
|
|
|
|
33
|
6 |
|
public function getValue() |
34
|
|
|
{ |
35
|
6 |
|
return $this->value; |
36
|
|
|
} |
37
|
|
|
|
38
|
6 |
|
public function setValue($value = null): void |
39
|
|
|
{ |
40
|
6 |
|
$this->value = $value; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
public function getParent() |
44
|
|
|
{ |
45
|
2 |
|
return $this->parent; |
46
|
|
|
} |
47
|
|
|
|
48
|
6 |
|
public function setParent($parent = null): void |
49
|
|
|
{ |
50
|
6 |
|
$this->parent = $parent; |
51
|
|
|
} |
52
|
|
|
|
53
|
6 |
|
public function getKey(): ?string |
54
|
|
|
{ |
55
|
6 |
|
return $this->key; |
56
|
|
|
} |
57
|
|
|
|
58
|
6 |
|
public function setKey(?string $key = null): void |
59
|
|
|
{ |
60
|
6 |
|
$this->key = self::processKey($key); |
61
|
|
|
} |
62
|
|
|
|
63
|
6 |
|
public function getContextKey(): ?string |
64
|
|
|
{ |
65
|
6 |
|
return $this->contextKey; |
66
|
|
|
} |
67
|
|
|
|
68
|
6 |
|
public function setContextKey(?string $contextKey = null): void |
69
|
|
|
{ |
70
|
6 |
|
$this->contextKey = self::processKey($contextKey); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getField(): string |
74
|
|
|
{ |
75
|
|
|
return $this->field; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setField(?string $field = null): void |
79
|
|
|
{ |
80
|
|
|
$this->field = $field; |
81
|
|
|
} |
82
|
|
|
|
83
|
6 |
|
public function getColumns(): ?array |
84
|
|
|
{ |
85
|
6 |
|
return $this->columns; |
86
|
|
|
} |
87
|
|
|
|
88
|
6 |
|
public function setColumns(?array $columns = null): void |
89
|
|
|
{ |
90
|
6 |
|
$this->columns = $columns; |
91
|
|
|
} |
92
|
|
|
|
93
|
6 |
|
public function getExpose(): bool |
94
|
|
|
{ |
95
|
6 |
|
return $this->expose; |
96
|
|
|
} |
97
|
|
|
|
98
|
6 |
|
public function setExpose(bool $expose): void |
99
|
|
|
{ |
100
|
6 |
|
$this->expose = $expose; |
101
|
|
|
} |
102
|
|
|
|
103
|
6 |
|
public function getProtected(): bool |
104
|
|
|
{ |
105
|
6 |
|
return $this->protected; |
106
|
|
|
} |
107
|
|
|
|
108
|
6 |
|
public function setProtected(bool $protected): void |
109
|
|
|
{ |
110
|
6 |
|
$this->protected = $protected; |
111
|
|
|
} |
112
|
|
|
|
113
|
6 |
|
public function getFullKey(): ?string |
114
|
|
|
{ |
115
|
6 |
|
$key = $this->getKey(); |
116
|
6 |
|
$keyContext = $this->getContextKey(); |
117
|
6 |
|
return $keyContext . (empty($key) ? null : (empty($keyContext) ? $key : '.' . $key)); |
118
|
|
|
} |
119
|
|
|
|
120
|
6 |
|
public static function processKey(?string $key = null): ?string |
121
|
|
|
{ |
122
|
6 |
|
return empty($key) || filter_var($key, FILTER_VALIDATE_INT) ? '' : mb_strtolower( |
123
|
6 |
|
trim( |
124
|
6 |
|
preg_replace( |
125
|
6 |
|
'/\.+/', |
126
|
6 |
|
'.', |
127
|
6 |
|
preg_replace( |
128
|
6 |
|
'/\s+/', |
129
|
6 |
|
'.', |
130
|
6 |
|
$key |
131
|
6 |
|
) |
132
|
6 |
|
), |
133
|
6 |
|
'.' |
134
|
6 |
|
) |
135
|
6 |
|
); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|