mirror of
https://github.com/Babibubebon/lodfe.git
synced 2024-09-23 01:34:21 +09:00
commit
a006acd1ec
8 changed files with 46 additions and 9 deletions
|
@ -1,4 +1,10 @@
|
||||||
lodfe
|
lodfe
|
||||||
=====
|
=====
|
||||||
|
SPARQLエンドポイントを用いたLinked Open Dataフロントエンド([Pubby](https://github.com/cygri/pubby)みたいなやつ)
|
||||||
|
|
||||||
SPARQLエンドポイントを用いたLinked Open Dataフロントエンド
|
## Installation
|
||||||
|
```
|
||||||
|
$ composer install
|
||||||
|
$ cp .env{.example,}
|
||||||
|
$ cp config/datasets.php{.example,}
|
||||||
|
```
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Middleware\ContentNegotiatorMiddleware;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class ResourceController extends Controller
|
class ResourceController extends Controller
|
||||||
|
@ -64,6 +65,8 @@ class ResourceController extends Controller
|
||||||
} catch (\EasyRdf_Exception $e) {
|
} catch (\EasyRdf_Exception $e) {
|
||||||
abort(400);
|
abort(400);
|
||||||
}
|
}
|
||||||
return $data;
|
$type = ContentNegotiatorMiddleware::mimetypeFromExtension($ext);
|
||||||
|
return response($data)
|
||||||
|
->header('Content-Type', $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,23 +9,34 @@ class ContentNegotiatorMiddleware
|
||||||
{
|
{
|
||||||
public $defaultType = 'text/html';
|
public $defaultType = 'text/html';
|
||||||
|
|
||||||
public $acceptableTypes = [
|
public static $acceptableTypes = [
|
||||||
'text/html' => 'html',
|
'text/html' => 'html',
|
||||||
'application/xhtml+xml' => 'html',
|
'application/xhtml+xml' => 'html',
|
||||||
'text/n3' => 'data',
|
'text/n3' => 'data',
|
||||||
'text/turtle' => 'data',
|
'text/turtle' => 'data',
|
||||||
'application/n-triples' => 'data',
|
'application/n-triples' => 'data',
|
||||||
'application/rdf+xml' => 'data',
|
'application/rdf+xml' => 'data',
|
||||||
|
'application/json' => 'data',
|
||||||
|
'application/ld+json' => 'data',
|
||||||
];
|
];
|
||||||
|
|
||||||
public $fileExtensions = [
|
public static $fileExtensions = [
|
||||||
'text/html' => '.html',
|
'text/html' => '.html',
|
||||||
'application/xhtml+xml' => '.html',
|
'application/xhtml+xml' => '.html',
|
||||||
'text/turtle' => '.ttl',
|
'text/turtle' => '.ttl',
|
||||||
'application/n-triples' => '.nt',
|
'application/n-triples' => '.nt',
|
||||||
'application/rdf+xml' => '.rdf',
|
'application/rdf+xml' => '.rdf',
|
||||||
|
'application/json' => '.json',
|
||||||
|
'application/ld+json' => '.jsonld',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function mimetypeFromExtension($ext)
|
||||||
|
{
|
||||||
|
$extensionToMimetype = array_flip(self::$fileExtensions);
|
||||||
|
return array_key_exists($ext, $extensionToMimetype)
|
||||||
|
? $extensionToMimetype[$ext] : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
*
|
*
|
||||||
|
@ -53,15 +64,15 @@ class ContentNegotiatorMiddleware
|
||||||
$id = $request->route('id');
|
$id = $request->route('id');
|
||||||
$negotiatedType = $this->defaultType;
|
$negotiatedType = $this->defaultType;
|
||||||
foreach ($accepts as $mime => $q) {
|
foreach ($accepts as $mime => $q) {
|
||||||
if (array_key_exists($mime, $this->acceptableTypes)) {
|
if (array_key_exists($mime, self::$acceptableTypes)) {
|
||||||
$negotiatedType = $mime;
|
$negotiatedType = $mime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirectTo = $this->acceptableTypes[$negotiatedType] . '.' . $datasetName;
|
$redirectTo = self::$acceptableTypes[$negotiatedType] . '.' . $datasetName;
|
||||||
$params = ['id' => $id];
|
$params = ['id' => $id];
|
||||||
if (substr($redirectTo, 0, 4) === 'data') {
|
if (substr($redirectTo, 0, 4) === 'data') {
|
||||||
$params['ext'] = $this->fileExtensions[$negotiatedType];
|
$params['ext'] = self::$fileExtensions[$negotiatedType];
|
||||||
}
|
}
|
||||||
return redirect()->route($redirectTo, $params, 303);
|
return redirect()->route($redirectTo, $params, 303);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,12 @@ $app->withFacades();
|
||||||
|
|
||||||
$app->configure('app');
|
$app->configure('app');
|
||||||
$app->configure('datasets');
|
$app->configure('datasets');
|
||||||
|
$app->configure('namespaces');
|
||||||
|
|
||||||
|
// Register namespaces
|
||||||
|
foreach (config('namespaces') as $prefix => $uri) {
|
||||||
|
EasyRdf_Namespace::set($prefix, $uri);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'version' => '1.0.0',
|
'version' => '1.1.0',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
5
config/namespaces.php
Normal file
5
config/namespaces.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'ma' => 'https://metadata.moe/ns/madb/ma#',
|
||||||
|
'madbdata' => 'https://metadata.moe/ns/madb/madbdata#',
|
||||||
|
];
|
|
@ -65,4 +65,8 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
@endforeach
|
@endforeach
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<script type="application/ld+json">
|
||||||
|
{!! $graph->serialise('jsonld') !!}
|
||||||
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
| and give it the Closure to call when that URI is requested.
|
| and give it the Closure to call when that URI is requested.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
if ($_SERVER['PHP_SELF'] === 'artisan') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function joinHostPort($components)
|
function joinHostPort($components)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue