+ try {
+ $compacted = jsonld_compact($jsonobj, $context);
+ }
+ catch (Exception $e) {
+ $compacted = false;
+ Logger::error('compacting error');
+ // Sooner or later we should log some details as well - but currently this leads to memory issues
+ // Logger::log('compacting error:' . substr(print_r($e, true), 0, 10000), Logger::DEBUG);
+ }
+
+ $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true);
+
+ if (isset($json['as:object']['as:source']['as:content']) && !empty($content)) {
+ $json['as:object']['as:source']['as:content'] = $content;
+ }
+
+ return $json;
+ }
+
+ /**
+ * @brief Fetches an element array from a JSON array
+ *
+ * @param $array
+ * @param $element
+ * @param $key
+ *
+ * @return array fetched element
+ */
+ public static function fetchElementArray($array, $element, $key = '@id')
+ {
+ if (empty($array)) {
+ return null;
+ }
+
+ if (!isset($array[$element])) {
+ return null;
+ }
+
+ // If it isn't an array yet, make it to one
+ if (!is_int(key($array[$element]))) {
+ $array[$element] = [$array[$element]];
+ }
+
+ $elements = [];
+
+ foreach ($array[$element] as $entry) {
+ if (!is_array($entry)) {
+ $elements[] = $entry;
+ } elseif (isset($entry[$key])) {
+ $elements[] = $entry[$key];
+ } elseif (!empty($entry) || !is_array($entry)) {
+ $elements[] = $entry;
+ }
+ }