Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class Server
private $basePath;
/** @var string */
private $baseUrl;
/** @var string */
private $lockedPath;
/** @var string */
private $requestedPath;
/** @var Filesystem */
private $filesystem;
/** @var Graph */
Expand Down Expand Up @@ -89,6 +93,11 @@ final public function setBaseUrl($url)
$this->basePath = $serverRequest->getUri()->getPath();
}

final public function lockToPath($path)
{
$this->lockedPath = $path;
}

final public function setNotifications(SolidNotificationsInterface $notifications)
{
$this->notifications = $notifications;
Expand All @@ -100,6 +109,7 @@ final public function __construct(Filesystem $filesystem, Response $response, ?G
{
$this->basePath = '';
$this->baseUrl = '';
$this->lockedPath = false;
$this->filesystem = $filesystem;
$this->graph = $graph ?? new Graph();
$this->response = $response;
Expand All @@ -121,6 +131,11 @@ final public function respondToRequest(Request $request): Response
$path = reset($slugs);
}

$this->requestedPath = $path;
if ($this->lockedPath) {
$path = $this->lockedPath;
}

$method = $this->getRequestMethod($request);

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

try {
// Assuming this is in our native format, turtle
$graph->parse($data, "turtle", $this->baseUrl . $path);
$graph->parse($data, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
// FIXME: Use enums from namespace Pdsinterop\Rdf\Enum\Format instead of 'turtle'?

// parse query in contents
Expand All @@ -297,14 +312,14 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
case "INSERT":
// insert $triple(s) into $graph
// @CHECKME: Does the Graph Parse here also need an URI?
$graph->parse($triples, "turtle"); // FIXME: The triples here are in sparql format, not in turtle;
$graph->parse($triples, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath); // FIXME: The triples here are in sparql format, not in turtle;

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

try {
// Assuming this is in our native format, turtle
// @CHECKME: Does the Graph Parse here also need an URI?
$graph->parse($data, "turtle");
// FIXME: Adding this base will allow us to parse <> entries; , $this->baseUrl . $this->basePath . $path), but that breaks the build.
$graph->parse($data, "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
// FIXME: Use enums from namespace Pdsinterop\Rdf\Enum\Format instead of 'turtle'?
$instructions = $this->n3Convert($contents);
foreach ($instructions as $key => $value) {
switch ($key) {
case "insert":
// error_log("INSERT");
// error_log($instructions['insert']);
$graph->parse($instructions['insert'], "turtle");
$graph->parse($instructions['insert'], "turtle", $this->baseUrl . $this->basePath . $this->requestedPath);
break;
case "delete":
$deleteGraph = $this->getGraph();
// error_log("DELETE");
// error_log($instructions['delete']);

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