1 | <?php |
||
14 | abstract class ContentfulMapper |
||
15 | { |
||
16 | |||
17 | use EntryType; |
||
18 | |||
19 | /** |
||
20 | * Map entry specific payload. |
||
21 | * |
||
22 | * @param array $entry |
||
23 | * @param string $locale |
||
24 | * @return array |
||
25 | * @throws \Exception |
||
26 | */ |
||
27 | abstract protected function map(array $entry, string $locale): array; |
||
28 | |||
29 | /** |
||
30 | * Map entry with common data + specific payload for each locales. |
||
31 | * |
||
32 | * @param array $entry |
||
33 | * @return array |
||
34 | * @throws \Exception |
||
35 | */ |
||
36 | public function toLocaleEntries(array $entry, Collection $locales): array |
||
74 | |||
75 | // -------------------------------------------------------------------------------- |
||
76 | // -------------------------------------------------------------------------------- |
||
77 | // -------------------------------------------------------------------------------- |
||
78 | |||
79 | /** |
||
80 | * Return raw entry fields payload for given locale. |
||
81 | * |
||
82 | * @param array $entry |
||
83 | * @param string $locale |
||
84 | * @return array |
||
85 | */ |
||
86 | protected function mapPayload(array $entry, string $locale): array |
||
111 | |||
112 | |||
113 | protected function levelFallBack($field) |
||
119 | |||
120 | // -------------------------------------------------------------------------------- |
||
121 | // -------------------------------------------------------------------------------- |
||
122 | // -------------------------------------------------------------------------------- |
||
123 | |||
124 | /** |
||
125 | * Map relationships in given payload. |
||
126 | * |
||
127 | * @param array $payload |
||
128 | * @return array |
||
129 | * @throws \Exception |
||
130 | */ |
||
131 | protected function mapRelationships($payload): array |
||
172 | |||
173 | /** |
||
174 | * Return relationship signature for given "localized" field. |
||
175 | * |
||
176 | * @param array $localeField |
||
177 | * @return array|null |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | private function relationshipSignature($localeField): ?array |
||
193 | |||
194 | /** |
||
195 | * Return if field is a Link one. |
||
196 | * |
||
197 | * @param mixed $localeField |
||
198 | * @return bool |
||
199 | */ |
||
200 | private function isLink($localeField): bool |
||
204 | |||
205 | /** |
||
206 | * Return contentful-type for given Contentful ID from `sync_entries` table. |
||
207 | * |
||
208 | * @param string $contentfulId |
||
209 | * @return string |
||
210 | * @throws \Exception |
||
211 | */ |
||
212 | public function contentTypeFromEntryTypes(string $contentfulId): string |
||
239 | |||
240 | // -------------------------------------------------------------------------------- |
||
241 | // -------------------------------------------------------------------------------- |
||
242 | // -------------------------------------------------------------------------------- |
||
243 | |||
244 | /** |
||
245 | * Return all locales in entry payload. |
||
246 | * |
||
247 | * @param array $entry |
||
248 | * @return array |
||
249 | */ |
||
250 | private function entryLocales(array $entry): array |
||
262 | } |
||
263 |