Fix expected implementation of JsonLD::fetchElementArray
- Added expected field value matching
This commit is contained in:
parent
61dcd62921
commit
fa003eaa84
|
@ -1345,7 +1345,7 @@ class Receiver
|
|||
$object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
|
||||
$object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment') ?? []);
|
||||
$object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag') ?? []);
|
||||
$object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', 'toot:Emoji') ?? []);
|
||||
$object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', null, '@type', 'toot:Emoji') ?? []);
|
||||
$object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
|
||||
$object_data['generator'] = JsonLD::fetchElement($object_data, 'generator', '@value');
|
||||
$object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url', '@id');
|
||||
|
|
|
@ -173,7 +173,7 @@ class JsonLD
|
|||
*
|
||||
* @return array fetched element
|
||||
*/
|
||||
public static function fetchElementArray($array, $element, $key = null)
|
||||
public static function fetchElementArray($array, $element, $key = null, $type = null, $type_value = null)
|
||||
{
|
||||
if (!isset($array[$element])) {
|
||||
return null;
|
||||
|
@ -187,10 +187,14 @@ class JsonLD
|
|||
$elements = [];
|
||||
|
||||
foreach ($array[$element] as $entry) {
|
||||
if (!is_array($entry) || (is_null($key) && is_array($entry))) {
|
||||
$elements[] = $entry;
|
||||
} elseif (!is_null($key) && isset($entry[$key])) {
|
||||
$elements[] = $entry[$key];
|
||||
if (!is_array($entry) || is_null($key)) {
|
||||
$item = $entry;
|
||||
} elseif (isset($entry[$key])) {
|
||||
$item = $entry[$key];
|
||||
}
|
||||
|
||||
if (isset($item) && (is_null($type) || is_null($type_value) || isset($item[$type]) && $item[$type] == $type_value)) {
|
||||
$elements[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue