Skip to content

Commit 5824233

Browse files
authored
Merge pull request #34 from pdsinterop/fix/uri-in-parse
use URI in parse. The breakage was caused by the pubsub server which has been fixed.
2 parents 4b97394 + 32d159a commit 5824233

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

src/Server.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class Server
5555
private $basePath;
5656
/** @var string */
5757
private $baseUrl;
58+
/** @var string */
59+
private $lockedPath;
60+
/** @var string */
61+
private $requestedPath;
5862
/** @var Filesystem */
5963
private $filesystem;
6064
/** @var Graph */
@@ -89,6 +93,11 @@ final public function setBaseUrl($url)
8993
$this->basePath = $serverRequest->getUri()->getPath();
9094
}
9195

96+
final public function lockToPath($path)
97+
{
98+
$this->lockedPath = $path;
99+
}
100+
92101
final public function setNotifications(SolidNotificationsInterface $notifications)
93102
{
94103
$this->notifications = $notifications;
@@ -100,6 +109,7 @@ final public function __construct(Filesystem $filesystem, Response $response, ?G
100109
{
101110
$this->basePath = '';
102111
$this->baseUrl = '';
112+
$this->lockedPath = false;
103113
$this->filesystem = $filesystem;
104114
$this->graph = $graph ?? new Graph();
105115
$this->response = $response;
@@ -121,6 +131,11 @@ final public function respondToRequest(Request $request): Response
121131
$path = reset($slugs);
122132
}
123133

134+
$this->requestedPath = $path;
135+
if ($this->lockedPath) {
136+
$path = $this->lockedPath;
137+
}
138+
124139
$method = $this->getRequestMethod($request);
125140

126141
$contents = $request->getBody()->getContents();
@@ -283,7 +298,7 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
283298

284299
try {
285300
// Assuming this is in our native format, turtle
286-
$graph->parse($data, "turtle", $this->baseUrl . $path);
301+
$graph->parse($data, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
287302
// FIXME: Use enums from namespace Pdsinterop\Rdf\Enum\Format instead of 'turtle'?
288303
289304
// parse query in contents
@@ -297,14 +312,14 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
297312
case "INSERT":
298313
// insert $triple(s) into $graph
299314
// @CHECKME: Does the Graph Parse here also need an URI?
300-
$graph->parse($triples, "turtle"); // FIXME: The triples here are in sparql format, not in turtle;
315+
$graph->parse($triples, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath); // FIXME: The triples here are in sparql format, not in turtle;
301316

302317
break;
303318
case "DELETE":
304319
// delete $triples from $graph
305320
$deleteGraph = $this->getGraph();
306321
// @CHECKME: Does the Graph Parse here also need an URI?
307-
$deleteGraph->parse($triples, "turtle"); // FIXME: The triples here are in sparql format, not in turtle;
322+
$deleteGraph->parse($triples, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath); // FIXME: The triples here are in sparql format, not in turtle;
308323
$resources = $deleteGraph->resources();
309324
foreach ($resources as $resource) {
310325
$properties = $resource->propertyUris();
@@ -440,25 +455,22 @@ private function handleN3Update(Response $response, string $path, $contents): Re
440455

441456
try {
442457
// Assuming this is in our native format, turtle
443-
// @CHECKME: Does the Graph Parse here also need an URI?
444-
$graph->parse($data, "turtle");
445-
// FIXME: Adding this base will allow us to parse <> entries; , $this->baseUrl . $this->basePath . $path), but that breaks the build.
458+
$graph->parse($data, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
446459
// FIXME: Use enums from namespace Pdsinterop\Rdf\Enum\Format instead of 'turtle'?
447460
$instructions = $this->n3Convert($contents);
448461
foreach ($instructions as $key => $value) {
449462
switch ($key) {
450463
case "insert":
451464
// error_log("INSERT");
452465
// error_log($instructions['insert']);
453-
$graph->parse($instructions['insert'], "turtle");
466+
$graph->parse($instructions['insert'], "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
454467
break;
455468
case "delete":
456469
$deleteGraph = $this->getGraph();
457470
// error_log("DELETE");
458471
// error_log($instructions['delete']);
459472

460-
// @CHECKME: Does the Graph Parse here also need an URI?
461-
$deleteGraph->parse($instructions['delete'], "turtle");
473+
$deleteGraph->parse($instructions['delete'], "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
462474
$resources = $deleteGraph->resources();
463475
foreach ($resources as $resource) {
464476
$properties = $resource->propertyUris();

0 commit comments

Comments
 (0)