Skip to content

Commit 600de06

Browse files
committed
Update documentation/clean up configuration format
Resolves #34
1 parent 66e58a7 commit 600de06

File tree

6 files changed

+89
-31
lines changed

6 files changed

+89
-31
lines changed

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# static-ldp
22

3-
A simple way to expose static HTTP assets as a read-only LDP server.
3+
A simple way to expose static assets as a read-only LDP server.
44

55
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net/)
66
[![Build Status](https://travis-ci.org/trellis-ldp/static-ldp.svg?branch=master)](https://travis-ci.org/trellis-ldp/static-ldp)
@@ -24,4 +24,53 @@ To install `static-ldp`, follow these steps:
2424

2525
1. clone this repository into a location on a webserver
2626
2. run `composer install`
27-
3. copy `config/settings.yml.sample` to `config/settings.yml` and update any values
27+
3. create a `./config/settings.yml` file like this:
28+
29+
sourceDirectory: /path/to/data/directory
30+
31+
## Configuration
32+
33+
There are many configuration options available. Only the `sourceDirectory` _must_ be defined.
34+
Other options include:
35+
36+
template: default.twig
37+
38+
If you wish to override the HTML template with one of your own design, you can change this
39+
value to point to a different location. Alternately, you can edit the `default.twig` file
40+
in the `templates` directory. Though if you plan to customize the template, it is recommended
41+
that you use a separate file.
42+
43+
defaultRdfFormat: turtle
44+
45+
For requests without an `Accept` header, this is the RDF format used in responses (for
46+
`ldp:RDFSource` and `ldp:BasicContainer` resources).
47+
48+
contentDisposition: false
49+
50+
For `ldp:NonRDFSource` resources, this controls whether to include a `Content-Disposition`
51+
header in responses.
52+
53+
validRdfFormats:
54+
turtle:
55+
mimeType: text/turtle
56+
extension: ttl
57+
jsonld:
58+
mimeType: application/ld+json
59+
extension: jsonld
60+
ntriples:
61+
mimeType: application/n-triples
62+
extension: nt
63+
64+
Generally speaking, the RDF formats should not be changed unless there is a need to
65+
support a serialization that is not included here. The RDF format (e.g. `turtle`,
66+
`jsonld`) must be an RDF serialization format supported by EasyRdf.
67+
68+
prefixes:
69+
dc: "http://purl.org/dc/terms/"
70+
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
71+
...
72+
73+
The default HTML display template will present IRIs in short (prefixed) form if those
74+
prefixes are registered. By default a number of common prefixes are included, but
75+
any prefix may be registered here.
76+

config/settings.yml.sample

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
sourceDirectory: /mnt/data/ldp/
22
template: default.twig
33
defaultRdfFormat: turtle
4+
contentDisposition: false
45
validRdfFormats:
5-
- { format: "turtle", mimeType: "text/turtle", extension : "ttl" }
6-
- { format: "jsonld", mimeType: "application/ld+json", extension: "jsonld" }
7-
- { format: "ntriples", mimeType: "application/n-triples", extension: "nt" }
6+
turtle:
7+
mimeType: "text/turtle"
8+
extension: ttl
9+
jsonld:
10+
mimeType: "application/ld+json"
11+
extension: jsonld
12+
ntriples:
13+
mimeType: "application/n-triples"
14+
extension: nt
815
prefixes:
916
dc: "http://purl.org/dc/terms/"
1017
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

src/Model/NonRDFSource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function respond(Application $app, Request $request, array $options = arr
3535
$res->headers->set('Digest', "sha1=" . $this->sha1());
3636
break;
3737
}
38-
foreach ($this->formats as $type) {
39-
$description = $this->path . "." . $type['extension'];
38+
foreach ($this->formats as $format => $data) {
39+
$description = $this->path . "." . $data['extension'];
4040
if (file_exists($description)) {
41-
$link = "<" . $request->getUri().".".$type['extension'].">; rel=\"describedby\"";
41+
$link = "<" . $request->getUri().".".$data['extension'].">; rel=\"describedby\"";
4242
$res->headers->set("Link", $link, false);
4343
}
4444
}

src/Model/RDFSource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ private function getInputFormat()
9898
{
9999
$filenameChunks = explode('.', $this->path);
100100
$extension = array_pop($filenameChunks);
101-
foreach ($this->formats as $type) {
102-
if ($type['extension'] == $extension) {
103-
return $type['format'];
101+
foreach ($this->formats as $format => $data) {
102+
if ($data['extension'] == $extension) {
103+
return $format;
104104
}
105105
}
106106
return null;

src/Model/Resource.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ protected function getResponseFormat(Request $request)
176176
if ($request->headers->has('accept')) {
177177
$accept = $request->getAcceptableContentTypes();
178178
foreach ($accept as $item) {
179-
$index = array_search($item, array_column($this->formats, 'mimeType'));
180-
if ($index !== false) {
181-
return $this->formats[$index]['format'];
179+
foreach ($this->formats as $format => $data) {
180+
if ($data['mimeType'] === $item) {
181+
return $format;
182+
}
182183
}
183184
if (strpos($item, "text/html") !== false) {
184185
return "html";
@@ -204,9 +205,10 @@ protected function getResponseMimeType(Request $request)
204205
if ($request->headers->has('accept')) {
205206
$accept = $request->getAcceptableContentTypes();
206207
foreach ($accept as $item) {
207-
$index = array_search($item, array_column($this->formats, 'mimeType'));
208-
if ($index !== false) {
209-
return $item;
208+
foreach ($this->formats as $format => $data) {
209+
if ($data['mimeType'] === $item) {
210+
return $item;
211+
}
210212
}
211213
if (strpos($item, "text/html") !== false) {
212214
return "text/html";

src/TrellisConfiguration.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ public function getConfigTreeBuilder()
3131
->defaultFalse()
3232
->end()
3333
->arrayNode('validRdfFormats')
34+
->useAttributeAsKey('format')
3435
->prototype("array")
3536
->children()
36-
->scalarNode('format')->end()
3737
->scalarNode('mimeType')->end()
3838
->scalarNode('extension')->end()
3939
->end()
4040
->end()
41-
->defaultValue([[
42-
"format" => "turtle",
43-
"mimeType" => "text/turtle",
44-
"extension" => "ttl"
45-
], [
46-
"format" => "jsonld",
47-
"mimeType" => "application/ld+json",
48-
"extension" => "jsonld"
49-
], [
50-
"format" => "ntriples",
51-
"mimeType" => "application/n-triples",
52-
"extension" => "nt"
53-
]])
41+
->defaultValue([
42+
"turtle" => [
43+
"mimeType" => "text/turtle",
44+
"extension" => "ttl"
45+
],
46+
"jsonld" => [
47+
"mimeType" => "application/ld+json",
48+
"extension" => "jsonld"
49+
],
50+
"ntriples" => [
51+
"mimeType" => "application/n-triples",
52+
"extension" => "nt"
53+
]])
5454
->end()
5555
->arrayNode('prefixes')
5656
->prototype('scalar')->end()

0 commit comments

Comments
 (0)