1 | <?php declare(strict_types=1); |
||
18 | class JsonParser extends ParserAbstract |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @param Document $document |
||
23 | * @param FeedInterface $feed |
||
24 | * @return FeedInterface |
||
25 | */ |
||
26 | 1 | public function parseContent(Document $document, FeedInterface $feed) : FeedInterface |
|
40 | |||
41 | /** |
||
42 | * @param Document $document |
||
43 | * @param iterable $mandatoryFields |
||
44 | * @throws MissingFieldsException |
||
45 | * @return bool |
||
46 | */ |
||
47 | 1 | public function checkBodyStructure(Document $document, iterable $mandatoryFields) : bool |
|
48 | { |
||
49 | 1 | $data = $document->getJsonAsArray(); |
|
50 | |||
51 | 1 | foreach ($mandatoryFields as $mandatoryField) { |
|
52 | 1 | if (! array_key_exists($mandatoryField, $data)) { |
|
53 | throw new MissingFieldsException("Missing {$mandatoryField} in the JSON Feed"); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | 1 | return true; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param iterable $items |
||
62 | * @param FeedInterface $feed |
||
63 | * @return JsonParser |
||
64 | */ |
||
65 | 1 | public function parseItems(iterable $items, FeedInterface $feed) : JsonParser |
|
80 | |||
81 | /** |
||
82 | * @param array $data |
||
83 | * @param string $offsetName |
||
84 | * @param string|null $default |
||
85 | * @return null|string |
||
86 | */ |
||
87 | 1 | public function readOffset(array $data, string $offsetName, string $default = null) : ? string |
|
95 | } |
||
96 |