1 | <?php |
||
23 | class StorageService implements Storage |
||
24 | { |
||
25 | const DIRECTION_UP = 'up'; |
||
26 | const DIRECTION_DOWN = 'down'; |
||
27 | |||
28 | /** |
||
29 | * @var Storage[] |
||
30 | */ |
||
31 | private $localStorages = []; |
||
32 | |||
33 | /** |
||
34 | * @var Storage[] |
||
35 | */ |
||
36 | private $remoteStorages = []; |
||
37 | |||
38 | /** |
||
39 | * Download all remote storages into all local storages. |
||
40 | * This will overwrite your local copy. |
||
41 | */ |
||
42 | public function download() |
||
46 | |||
47 | /** |
||
48 | * Upload all local storages into all remote storages |
||
49 | * This will overwrite your remote copy. |
||
50 | */ |
||
51 | public function upload() |
||
55 | |||
56 | /** |
||
57 | * Synchronize translations with remote. |
||
58 | */ |
||
59 | public function sync($direction = self::DIRECTION_DOWN) |
||
74 | |||
75 | /** |
||
76 | * Download and merge all translations from remote storages down to your local storages. |
||
77 | * Only the local storages will be changed. |
||
78 | */ |
||
79 | public function mergeDown() |
||
83 | |||
84 | /** |
||
85 | * Upload and merge all translations from local storages up to your remote storages. |
||
86 | * Only the remote storages will be changed. |
||
87 | */ |
||
88 | public function mergeUp() |
||
92 | |||
93 | /** |
||
94 | * Get the very latest version we know of a message. First look at the remote storage |
||
95 | * fall back on the local ones. |
||
96 | * |
||
97 | * @param string $locale |
||
98 | * @param string $domain |
||
99 | * @param string $key |
||
100 | * |
||
101 | * @return null|Message |
||
102 | */ |
||
103 | public function syncAndFetchMessage($locale, $domain, $key) |
||
115 | |||
116 | /** |
||
117 | * Try to get a translation from all the storages, start looking in the first |
||
118 | * local storage and then move on to the remote storages. |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function get($locale, $domain, $key) |
||
132 | |||
133 | /** |
||
134 | * @param Storage[] $storages |
||
135 | * @param string $locale |
||
136 | * @param string $domain |
||
137 | * @param string $key |
||
138 | * |
||
139 | * @return null|Message |
||
140 | */ |
||
141 | private function getFromStorages($storages, $locale, $domain, $key) |
||
152 | |||
153 | /** |
||
154 | * Update all configured storages with this message. |
||
155 | * |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | public function update(Message $message) |
||
164 | |||
165 | /** |
||
166 | * @param Storage[] $storages |
||
167 | * @param Message $message |
||
168 | */ |
||
169 | private function updateStorages($storages, Message $message) |
||
180 | |||
181 | /** |
||
182 | * Delete the message form all storages. |
||
183 | * |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function delete($locale, $domain, $key) |
||
192 | |||
193 | /** |
||
194 | * @param Storage[] $storages |
||
195 | * @param string $locale |
||
196 | * @param string $domain |
||
197 | * @param string $key |
||
198 | */ |
||
199 | private function deleteFromStorages($storages, $locale, $domain, $key) |
||
205 | |||
206 | /** |
||
207 | * @param Storage $localStorage |
||
208 | * |
||
209 | * @return StorageService |
||
210 | */ |
||
211 | public function addLocalStorage(Storage $localStorage) |
||
217 | |||
218 | /** |
||
219 | * @param Storage $remoteStorages |
||
220 | * |
||
221 | * @return StorageService |
||
222 | */ |
||
223 | public function addRemoteStorage(Storage $remoteStorage) |
||
229 | } |
||
230 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: