|
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
|
|
|
public function getValue() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->value; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function setValue($value = null): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->value = $value; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getParent() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->parent; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setParent($parent = null): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->parent = $parent; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getKey(): ?string |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->key; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setKey(?string $key = null): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->key = self::processKey($key); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getContextKey(): ?string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->contextKey; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function setContextKey(?string $contextKey = null): void |
|
69
|
|
|
{ |
|
70
|
|
|
$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
|
|
|
public function getColumns(): ?array |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->columns; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setColumns(?array $columns = null): void |
|
89
|
|
|
{ |
|
90
|
|
|
$this->columns = $columns; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getExpose(): bool |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->expose; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setExpose(bool $expose): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->expose = $expose; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getProtected(): bool |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->protected; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function setProtected(bool $protected): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->protected = $protected; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getFullKey(): ?string |
|
114
|
|
|
{ |
|
115
|
|
|
$key = $this->getKey(); |
|
116
|
|
|
$keyContext = $this->getContextKey(); |
|
117
|
|
|
return $keyContext . (empty($key) ? null : (empty($keyContext) ? $key : '.' . $key)); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public static function processKey(?string $key = null): ?string |
|
121
|
|
|
{ |
|
122
|
|
|
return empty($key)? $key : mb_strtolower( |
|
123
|
|
|
trim( |
|
124
|
|
|
preg_replace( |
|
125
|
|
|
'/\.+/', |
|
126
|
|
|
'.', |
|
127
|
|
|
preg_replace( |
|
128
|
|
|
'/\s+/', |
|
129
|
|
|
'.', |
|
130
|
|
|
$key |
|
131
|
|
|
) |
|
132
|
|
|
), |
|
133
|
|
|
'.' |
|
134
|
|
|
) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|