1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpWinTools\WmiScripting\Concerns; |
4
|
|
|
|
5
|
|
|
use function PhpWinTools\WmiScripting\Support\get_ancestor_property; |
6
|
|
|
|
7
|
|
|
trait HasHiddenAttributes |
8
|
|
|
{ |
9
|
|
|
protected $hidden_booted = false; |
10
|
|
|
|
11
|
|
|
protected $trait_hidden_attributes = [ |
12
|
|
|
'trait_hidden_attributes', |
13
|
|
|
'trait_name_replacements', |
14
|
|
|
|
15
|
|
|
'attribute_name_replacements', |
16
|
|
|
'unmapped_attributes', |
17
|
|
|
|
18
|
|
|
'hidden_attributes', |
19
|
|
|
'merge_parent_hidden_attributes', |
20
|
|
|
|
21
|
|
|
'attribute_casting', |
22
|
|
|
'merge_parent_casting', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
public function mergeHiddenAttributes(array $hidden_attributes, bool $merge_hidden = true) |
26
|
|
|
{ |
27
|
|
|
$hidden_attributes = $merge_hidden |
28
|
|
|
? array_merge(get_ancestor_property(get_called_class(), 'hidden_attributes'), $hidden_attributes) |
29
|
|
|
: $hidden_attributes; |
30
|
|
|
|
31
|
|
|
$this->trait_hidden_attributes = array_merge($this->trait_hidden_attributes, $hidden_attributes); |
32
|
|
|
|
33
|
|
|
$this->bootHiddenAttributes(); |
34
|
|
|
|
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getHiddenAttributes() |
39
|
|
|
{ |
40
|
|
|
if (!$this->hidden_booted) { |
41
|
|
|
$this->bootHiddenAttributes(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->trait_hidden_attributes; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function isHidden($key): bool |
48
|
|
|
{ |
49
|
|
|
return array_key_exists($key, $this->getHiddenAttributes()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function bootHiddenAttributes() |
53
|
|
|
{ |
54
|
|
|
$this->trait_hidden_attributes = array_combine($this->trait_hidden_attributes, $this->trait_hidden_attributes); |
55
|
|
|
|
56
|
|
|
$this->hidden_booted = true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|