handling mime type first take
davvalent

davvalent commited on 2023-03-13 22:17:37
Showing 1 changed files, with 34 additions and 1 deletions.

... ...
@@ -123,7 +123,40 @@
123 123
 
124 124
   $triples = use_path_to_query($q, $store);
125 125
 
126
+  if (!$triples['result']) {
127
+    echo "SPARQL query returned 0 result";
128
+    exit();
129
+  }
130
+
131
+  /** json-ld */
132
+  if ($accept_header == 'application/ld+json') {
133
+
134
+  $graph = new \EasyRdf\Graph(/*'http://data.qdmtl.ca/' . $path*/);
135
+
136
+    $graph->parse($triples['result']);
137
+//    echo $graph->dump('html');exit();
138
+//    var_dump($graph);exit();
139
+
140
+    $jsonld = $graph->serialise('application/ld+json', array(
141
+      'expand_native_types' => null,
142
+      'compact' => true,
143
+      'context' => './qdmtl-context.jsonld',
144
+      'expand' => null,
145
+      'frame' => null
146
+    ));
126 147
 
148
+    if (!is_scalar($jsonld)) {
149
+          $jsonld = var_export($jsonld, true);
150
+        }
151
+
152
+    header('Content-type: application/ld+json');  
153
+    echo $jsonld;
154
+    exit();
155
+  }
156
+
157
+  /** RDF/XML */
158
+  $rdf_xml_serialization = $rdf_xml_serializer->getSerializedIndex($triples['result']);
127 159
   header('Content-type: text/xml');
128
-  echo $doc;
160
+  echo $rdf_xml_serialization;
161
+
129 162
 ?>
130 163
\ No newline at end of file
131 164