22
33namespace Pdsinterop \Solid \Resources ;
44
5- use EasyRdf \Format ;
65use Pdsinterop \Solid \SolidNotifications \SolidNotificationsInterface ;
76use EasyRdf \Exception as RdfException ;
87use 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 ;
0 commit comments