| Conditions | 2 |
| Paths | 6 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | public function resolve(int $timeout): ?EasyRdf\Resource |
||
| 6 | { |
||
| 7 | // prevent parsing errors for sources which return invalid JSON (see #447) |
||
| 8 | // 1. Unregister the legacy RDF/JSON parser, we don't want to use it |
||
| 9 | EasyRdf\Format::unregister('json'); |
||
| 10 | // 2. Add "application/json" as a possible MIME type for the JSON-LD format |
||
| 11 | $jsonld = EasyRdf\Format::getFormat('jsonld'); |
||
| 12 | $mimetypes = $jsonld->getMimeTypes(); |
||
| 13 | $mimetypes['application/json'] = 0.5; |
||
| 14 | $jsonld->setMimeTypes($mimetypes); |
||
| 15 | |||
| 16 | try { |
||
| 17 | // change the timeout setting for external requests |
||
| 18 | $httpclient = EasyRdf\Http::getDefaultHttpClient(); |
||
| 19 | $httpclient->setConfig(array('timeout' => $timeout, 'useragent' => 'Skosmos')); |
||
| 20 | EasyRdf\Http::setDefaultHttpClient($httpclient); |
||
| 21 | |||
| 22 | $graph = EasyRdf\Graph::newAndLoad(EasyRdf\Utils::removeFragmentFromUri($this->uri)); |
||
| 23 | return $graph->resource($this->uri); |
||
| 24 | } catch (Exception $e) { |
||
| 25 | $this->model->getLogger()->info("LD resolution failed for <{$this->uri}>: $e"); |
||
| 26 | return null; |
||
| 27 | } |
||
| 32 |