1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Core\Concern; |
4: | |
5: | use Salient\Contract\Core\Entity\Extensible; |
6: | use Salient\Core\Internal\ReadPropertyTrait; |
7: | use Salient\Core\Internal\WritePropertyTrait; |
8: | use Salient\Utility\Arr; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | trait ExtensibleTrait |
18: | { |
19: | use ReadPropertyTrait; |
20: | use WritePropertyTrait; |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | protected $MetaProperties = []; |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | protected $MetaPropertyNames = []; |
35: | |
36: | |
37: | |
38: | |
39: | public static function getDynamicPropertiesProperty(): string |
40: | { |
41: | return 'MetaProperties'; |
42: | } |
43: | |
44: | |
45: | |
46: | |
47: | public static function getDynamicPropertyNamesProperty(): string |
48: | { |
49: | return 'MetaPropertyNames'; |
50: | } |
51: | |
52: | |
53: | |
54: | |
55: | final public function setDynamicProperties(array $values): void |
56: | { |
57: | $this->MetaProperties = []; |
58: | $this->MetaPropertyNames = []; |
59: | |
60: | foreach ($values as $name => $value) { |
61: | $this->__set($name, $value); |
62: | } |
63: | } |
64: | |
65: | final public function getDynamicProperties(): array |
66: | { |
67: | return Arr::combine( |
68: | array_map( |
69: | fn(string $name): string => $this->MetaPropertyNames[$name], |
70: | array_keys($this->MetaProperties) |
71: | ), |
72: | $this->MetaProperties |
73: | ); |
74: | } |
75: | } |
76: | |