Completed
Push — master ( 751599...c13dee )
by Osma
02:10 queued 10s
created

Resolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
class Resolver
4
{
5
    private $model;
6
7
    /**
8
     * Initializes the Resolver object
9
     */
10
    public function __construct($model)
11
    {
12
        $this->model = $model;
13
    }
14
15
    private function startsWith(string $prefix, string $target) : bool {
16
        return strpos($target, $prefix) === 0;
17
    }
18
19
    /**
20
     * Resolve the URI using the most appropriate resolver and return the
21
     * result as an ExternalResource.
22
     * @param string $uri URI to resolve
23
     * @return EasyRdf\Resource
24
     */
25
    public function resolve(string $uri, int $timeout): ?EasyRdf\Resource {
26
        if (preg_match('|http://id.loc.gov/[^/]+/[^/]+/.+|', $uri)) {
27
            $res = new LOCResource($this->model, $uri);
28
        } elseif ($this->startsWith('http://www.wikidata.org/entity/', $uri)) {
29
            $res = new WDQSResource($this->model, $uri);
30
        } else {
31
            $res = new LinkedDataResource($this->model, $uri);
32
        }
33
        return $res->resolve($timeout);
34
    }
35
}
36