1 | <?php namespace Limoncello\Application\Settings; |
||
28 | class CacheSettingsProvider implements CacheSettingsProviderInterface |
||
29 | { |
||
30 | /** Internal data index */ |
||
31 | const KEY_APPLICATION_CONFIGURATION = 0; |
||
32 | |||
33 | /** Internal data index */ |
||
34 | const KEY_CORE_DATA = self::KEY_APPLICATION_CONFIGURATION + 1; |
||
35 | |||
36 | /** Internal data index */ |
||
37 | const KEY_SETTINGS_MAP = self::KEY_CORE_DATA + 1; |
||
38 | |||
39 | /** Internal data index */ |
||
40 | const KEY_SETTINGS_DATA = self::KEY_SETTINGS_MAP + 1; |
||
41 | |||
42 | /** Internal data index */ |
||
43 | const KEY_AMBIGUOUS_MAP = self::KEY_SETTINGS_DATA + 1; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | private $appConfig = []; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | private $coreData = []; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | private $settingsMap = []; |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | private $settingsData = []; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | private $ambiguousMap = []; |
||
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | 3 | public function get(string $className): array |
|
74 | { |
||
75 | 3 | if ($this->has($className) === false) { |
|
76 | 2 | if (array_key_exists($className, $this->ambiguousMap) === true) { |
|
77 | 1 | throw new AmbiguousSettingsException($className); |
|
78 | } |
||
79 | 1 | throw new NotRegisteredSettingsException($className); |
|
80 | } |
||
81 | |||
82 | 1 | $data = $this->settingsData[$this->settingsMap[$className]]; |
|
83 | |||
84 | 1 | return $data; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | 1 | public function getApplicationConfiguration(): array |
|
91 | { |
||
92 | 1 | return $this->appConfig; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | 2 | public function getCoreData(): array |
|
102 | |||
103 | /** |
||
104 | * @inheritdoc |
||
105 | */ |
||
106 | 3 | public function has(string $className): bool |
|
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | 1 | public function isAmbiguous(string $className): bool |
|
122 | |||
123 | /** |
||
124 | * @param ApplicationConfigurationInterface $appConfig |
||
125 | * @param CoreData $coreData |
||
126 | * @param InstanceSettingsProvider $provider |
||
127 | * |
||
128 | * @return self |
||
129 | */ |
||
130 | 6 | public function setInstanceSettings( |
|
145 | |||
146 | /** |
||
147 | * @inheritdoc |
||
148 | */ |
||
149 | 2 | public function serialize(): array |
|
159 | |||
160 | /** |
||
161 | * @inheritdoc |
||
162 | */ |
||
163 | 6 | public function unserialize(array $serialized): void |
|
173 | } |
||
174 |