Signed-off-by: Christian Wolf <github@christianwolf.email>
This commit is contained in:
Christian Wolf 2021-10-20 14:51:09 +02:00
Родитель 19b6f43657
Коммит e3a57a712e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9FC3120E932F73F1
1 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -71,6 +71,9 @@ class HttpJsonLdParser extends AbstractHtmlParser {
// Look for an array of recipes
$this->mapArray($json);
// Ensure the type of the object is never an array
$this->checkForArrayType($json);
if ($this->jsonService->isSchemaObject($json, 'Recipe')) {
// We found our recipe
return $json;
@ -165,4 +168,22 @@ class HttpJsonLdParser extends AbstractHtmlParser {
// No recipe was found
return null;
}
/**
* Check if the JSON element is a schema.org object but malformed.
*
* This checks if the '@type' entry is an array and corrects that.
*
* @param array $json The JSON object to parse
* @return void
*/
private function checkForArrayType(array &$json) {
if (! $this->jsonService->isSchemaObject($json)) {
return;
}
if (is_array($json['@type'])) {
$json['@type'] = $json['@type'][0];
}
}
}