Skip to content

Commit 71bc42b

Browse files
committed
Change Server to re-use inject Graph rather than creating new ones.
1 parent 681e19f commit 71bc42b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/Server.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Server
4545
private $baseUrl;
4646
/** @var Filesystem */
4747
private $filesystem;
48+
/** @var Graph */
49+
private $graph;
4850
/** @var string */
4951
private $pubsub;
5052
/** @var Response */
@@ -62,6 +64,11 @@ final public function getResponse()
6264
return $this->response;
6365
}
6466

67+
private function getGraph(): Graph
68+
{
69+
return clone $this->graph;
70+
}
71+
6572
final public function setBaseUrl($url)
6673
{
6774
$this->baseUrl = $url;
@@ -77,12 +84,14 @@ final public function setPubSubUrl($url)
7784

7885
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
7986

80-
final public function __construct(Filesystem $filesystem, Response $response)
87+
// @TODO: The Graph should be injected by the caller
88+
final public function __construct(Filesystem $filesystem, Response $response, Graph $graph = null)
8189
{
8290
$this->basePath = '';
8391
$this->baseUrl = '';
8492
$this->pubsub = '';
8593
$this->filesystem = $filesystem;
94+
$this->graph = $graph ?? new Graph();
8695
$this->response = $response;
8796
}
8897

@@ -249,7 +258,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
249258
private function handleSparqlUpdate(Response $response, string $path, $contents): Response
250259
{
251260
$filesystem = $this->filesystem;
252-
$graph = new Graph();
261+
$graph = $this->getGraph();
253262

254263
if ($filesystem->has($path) === false) {
255264
$data = '';
@@ -279,7 +288,7 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
279288
break;
280289
case "DELETE":
281290
// delete $triples from $graph
282-
$deleteGraph = new Graph();
291+
$deleteGraph = $this->getGraph();
283292
$deleteGraph->parse($triples, "turtle"); // FIXME: The triples here are in sparql format, not in turtle;
284293
$resources = $deleteGraph->resources();
285294
foreach ($resources as $resource) {

0 commit comments

Comments
 (0)