Skip to content

Commit 68ff557

Browse files
committed
simpler version of the fix with modified unit tests to accomodate that
1 parent ad0adaf commit 68ff557

2 files changed

Lines changed: 26 additions & 28 deletions

File tree

src/Server.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Pdsinterop\Solid\Resources;
44

5-
use EasyRdf\Format;
65
use Pdsinterop\Solid\SolidNotifications\SolidNotificationsInterface;
76
use EasyRdf\Exception as RdfException;
87
use EasyRdf\Graph as Graph;
@@ -114,10 +113,6 @@ final public function __construct(Filesystem $filesystem, Response $response, ?G
114113
$this->filesystem = $filesystem;
115114
$this->graph = $graph ?? new Graph();
116115
$this->response = $response;
117-
118-
// Store and serve json-ld with '.json' extension instead of '.jsonld''
119-
Format::getFormat('jsonld')->setExtensions('json');
120-
121116
// @TODO: Mention \EasyRdf_Namespace::set('lm', 'https://purl.org/pdsinterop/link-metadata#');
122117
}
123118

@@ -211,8 +206,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
211206
$response = $response->withStatus(400);
212207
break;
213208
}
214-
break;
215-
209+
break;
216210
case 'POST':
217211
$pathExists = $filesystem->has($path);
218212
if ($pathExists) {
@@ -222,7 +216,6 @@ private function handle(string $method, string $path, $contents, $request): Resp
222216
$pathExists = true;
223217
$mimetype = self::MIME_TYPE_DIRECTORY;
224218
}
225-
226219
if ($pathExists === true) {
227220
if (isset($mimetype) && $mimetype === self::MIME_TYPE_DIRECTORY) {
228221
$contentType= explode(";", $request->getHeaderLine("Content-Type"))[0];
@@ -231,6 +224,25 @@ private function handle(string $method, string $path, $contents, $request): Resp
231224
$filename = $slug;
232225
} else {
233226
$filename = $this->guid();
227+
// FIXME: make this list complete for at least the things we'd expect (turtle, n3, jsonld, ntriples, rdf);
228+
switch ($contentType) {
229+
case '':
230+
// FIXME: if no content type was passed, we should reject the request according to the spec;
231+
break;
232+
case "text/plain":
233+
$filename .= ".txt";
234+
break;
235+
case "text/turtle":
236+
$filename .= ".ttl";
237+
break;
238+
case "text/html":
239+
$filename .= ".html";
240+
break;
241+
case "application/json":
242+
case "application/ld+json":
243+
$filename .= ".json";
244+
break;
245+
}
234246
}
235247

236248
$link = $request->getHeaderLine("Link");
@@ -239,18 +251,6 @@ private function handle(string $method, string $path, $contents, $request): Resp
239251
$response = $this->handleCreateDirectoryRequest($response, $path . $filename);
240252
break;
241253
default:
242-
// FIXME: if no content type was passed, we should reject the request according to the spec;
243-
foreach (Format::getFormats() as $format) {
244-
$mimeTypes = array_keys($format->getMimeTypes());
245-
foreach ($mimeTypes as $mimeType) {
246-
$extensions[$mimeType] = '.'.$format->getDefaultExtension();
247-
}
248-
}
249-
250-
if (isset($extensions[$contentType]) && ! str_ends_with($filename, $extensions[$contentType])) {
251-
$filename .= $extensions[$contentType];
252-
}
253-
254254
$response = $this->handleCreateRequest($response, $path . $filename, $contents);
255255
break;
256256
}
@@ -260,8 +260,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
260260
} else {
261261
$response = $this->handleCreateRequest($response, $path, $contents);
262262
}
263-
break;
264-
263+
break;
265264
case 'PUT':
266265
$link = $request->getHeaderLine("Link");
267266
switch ($link) {
@@ -276,8 +275,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
276275
}
277276
break;
278277
}
279-
break;
280-
278+
break;
281279
default:
282280
throw Exception::create(self::ERROR_UNKNOWN_HTTP_METHOD, [$method]);
283281
break;

tests/unit/ServerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ public static function provideSlugs()
180180
return [
181181
// '' => [$slug, $mimetype, $expectedFilename],
182182
'Slug with json extension, with ld+json MIME' => ['Mock Slug.json', 'application/ld+json', 'Mock Slug.json'],
183-
'Slug with jsonld extension, with ld+json MIME)' => ['Mock Slug.jsonld', 'application/ld+json', 'Mock Slug.jsonld.json'],
183+
'Slug with jsonld extension, with ld+json MIME' => ['Mock Slug.jsonld', 'application/ld+json', 'Mock Slug.jsonld'],
184184
'Slug with PNG extension, with PNG MIME' => ['Mock Slug.png', 'image/png', 'Mock Slug.png'],
185-
'Slug with some other, extension) with Turtle MIME' => ['Mock Slug.other', 'text/turtle', 'Mock Slug.other.ttl'],
185+
'Slug with some other, extension) with Turtle MIME' => ['Mock Slug.other', 'text/turtle', 'Mock Slug.other'],
186186
'Slug with Turtle extension, with other MIME' => ['Mock Slug.ttl', 'some/other', 'Mock Slug.ttl'],
187187
'Slug with Turtle extension, with Turtle MIME' => ['Mock Slug.ttl', 'text/turtle', 'Mock Slug.ttl'],
188-
'Slug without extension), with some other MIME' => ['Mock Slug', 'some/other', 'Mock Slug'],
189-
'Slug without extension), with turtle MIME' => ['Mock Slug', 'text/turtle', 'Mock Slug.ttl'],
188+
'Slug without extension, with some other MIME' => ['Mock Slug', 'some/other', 'Mock Slug'],
189+
'Slug without extension, with turtle MIME' => ['Mock Slug', 'text/turtle', 'Mock Slug'],
190190
];
191191
}
192192

0 commit comments

Comments
 (0)