equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 namespace CorpusParole\Http\Controllers\Api; |
|
4 |
|
5 use Illuminate\Http\Request; |
|
6 use CorpusParole\Http\Requests; |
|
7 use CorpusParole\Http\Controllers\Controller; |
|
8 use CorpusParole\Services\BnfResolverInterface; |
|
9 use CorpusParole\Services\BnfResolverException; |
|
10 |
|
11 class BnfController extends Controller |
|
12 { |
|
13 public function __construct(BnfResolverInterface $bnfResolver) { |
|
14 $this->bnfResolver = $bnfResolver; |
|
15 } |
|
16 |
|
17 public function index() { |
|
18 return print_r($this->bnfResolver, true); |
|
19 } |
|
20 |
|
21 /** |
|
22 * Display the specified resource. |
|
23 * |
|
24 * @param int $id od comma separated list of ids |
|
25 * @return \Illuminate\Http\Response |
|
26 */ |
|
27 public function show($id) |
|
28 { |
|
29 $ids = array_map(function($rid) { return (strpos($rid,"ark:/12148")===0)?$rid:"ark:/12148/$rid"; },explode(",", $id)); |
|
30 try { |
|
31 return response()->json(['bnfids' => $this->bnfResolver->getLabels($ids)]); |
|
32 } catch (BnfResolverException $e) { |
|
33 abort(500, $e->getMessage()); |
|
34 } |
|
35 } |
|
36 |
|
37 } |