1 | <?php |
||
6 | final class CustomizableAppConfig implements ArraySerializableInterface |
||
7 | { |
||
8 | const SQLITE_DB_PATH = 'data/database.sqlite'; |
||
9 | |||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | private $database; |
||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private $urlShortener; |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $language; |
||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $app; |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $importedInstallationPath; |
||
30 | |||
31 | /** |
||
32 | * @return array |
||
33 | */ |
||
34 | 4 | public function getDatabase() |
|
38 | |||
39 | /** |
||
40 | * @param array $database |
||
41 | * @return $this |
||
42 | */ |
||
43 | 4 | public function setDatabase(array $database) |
|
48 | |||
49 | /** |
||
50 | * @return bool |
||
51 | */ |
||
52 | 4 | public function hasDatabase() |
|
56 | |||
57 | /** |
||
58 | * @return array |
||
59 | */ |
||
60 | 3 | public function getUrlShortener() |
|
64 | |||
65 | /** |
||
66 | * @param array $urlShortener |
||
67 | * @return $this |
||
68 | */ |
||
69 | 3 | public function setUrlShortener(array $urlShortener) |
|
74 | |||
75 | /** |
||
76 | * @return bool |
||
77 | */ |
||
78 | 3 | public function hasUrlShortener() |
|
82 | |||
83 | /** |
||
84 | * @return array |
||
85 | */ |
||
86 | 3 | public function getLanguage() |
|
90 | |||
91 | /** |
||
92 | * @param array $language |
||
93 | * @return $this |
||
94 | */ |
||
95 | 3 | public function setLanguage(array $language) |
|
100 | |||
101 | /** |
||
102 | * @return bool |
||
103 | */ |
||
104 | 3 | public function hasLanguage() |
|
108 | |||
109 | /** |
||
110 | * @return array |
||
111 | */ |
||
112 | 3 | public function getApp() |
|
116 | |||
117 | /** |
||
118 | * @param array $app |
||
119 | * @return $this |
||
120 | */ |
||
121 | 3 | public function setApp(array $app) |
|
126 | |||
127 | /** |
||
128 | * @return bool |
||
129 | */ |
||
130 | 3 | public function hasApp() |
|
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | 2 | public function getImportedInstallationPath() |
|
142 | |||
143 | /** |
||
144 | * @param string $importedInstallationPath |
||
145 | * @return $this|self |
||
146 | */ |
||
147 | 1 | public function setImportedInstallationPath($importedInstallationPath) |
|
152 | |||
153 | /** |
||
154 | * @return bool |
||
155 | */ |
||
156 | public function hasImportedInstallationPath() |
||
160 | |||
161 | /** |
||
162 | * Exchange internal values from provided array |
||
163 | * |
||
164 | * @param array $array |
||
165 | * @return void |
||
166 | */ |
||
167 | 1 | public function exchangeArray(array $array) |
|
168 | { |
||
169 | 1 | if (isset($array['app_options'], $array['app_options']['secret_key'])) { |
|
170 | $this->setApp([ |
||
171 | 'SECRET' => $array['app_options']['secret_key'], |
||
172 | ]); |
||
173 | } |
||
174 | |||
175 | 1 | if (isset($array['entity_manager'], $array['entity_manager']['connection'])) { |
|
176 | $this->deserializeDatabase($array['entity_manager']['connection']); |
||
177 | } |
||
178 | |||
179 | 1 | if (isset($array['translator'], $array['translator']['locale'], $array['cli'], $array['cli']['locale'])) { |
|
180 | $this->setLanguage([ |
||
181 | 'DEFAULT' => $array['translator']['locale'], |
||
182 | 'CLI' => $array['cli']['locale'], |
||
183 | ]); |
||
184 | } |
||
185 | |||
186 | 1 | if (isset($array['url_shortener'])) { |
|
187 | $urlShortener = $array['url_shortener']; |
||
188 | $this->setUrlShortener([ |
||
189 | 'SCHEMA' => $urlShortener['domain']['schema'], |
||
190 | 'HOSTNAME' => $urlShortener['domain']['hostname'], |
||
191 | 'CHARS' => $urlShortener['shortcode_chars'], |
||
192 | 'VALIDATE_URL' => $urlShortener['validate_url'], |
||
193 | ]); |
||
194 | } |
||
195 | 1 | } |
|
196 | |||
197 | private function deserializeDatabase(array $conn) |
||
215 | |||
216 | /** |
||
217 | * Return an array representation of the object |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | 3 | public function getArrayCopy() |
|
267 | } |
||
268 |