1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under |
5
|
|
|
* the terms of the GPL-3 license. |
6
|
|
|
* |
7
|
|
|
* (c) Konrad Abicht <[email protected]> |
8
|
|
|
* (c) Benjamin Nowack |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace sweetrdf\InMemoryStoreSqlite; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* This class provides helpers to handle RDF namespace related operations. |
18
|
|
|
*/ |
19
|
|
|
final class NamespaceHelper |
20
|
|
|
{ |
21
|
|
|
const BASE_NAMESPACE = 'sweetrdf://in-memory-store-sqlite/'; |
22
|
|
|
|
23
|
|
|
const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; |
24
|
|
|
const NAMESPACE_XML = 'http://www.w3.org/XML/1998/namespace'; |
25
|
|
|
const NAMESPACE_XSD = 'http://www.w3.org/2001/XMLSchema#'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* List of known and new namespaces + prefixes. |
29
|
|
|
* |
30
|
|
|
* @var array<string,string> |
31
|
|
|
*/ |
32
|
|
|
private array $namespaces = [ |
33
|
|
|
'owl:' => 'http://www.w3.org/2002/07/owl#', |
34
|
|
|
'rdf:' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
35
|
|
|
'rdfs:' => 'http://www.w3.org/2000/01/rdf-schema#', |
36
|
|
|
'xsd:' => 'http://www.w3.org/2001/XMLSchema#', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array<string,string> |
41
|
|
|
*/ |
42
|
88 |
|
public function getNamespaces(): array |
43
|
|
|
{ |
44
|
88 |
|
return $this->namespaces; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get namespace by prefix. |
49
|
|
|
*/ |
50
|
19 |
|
public function getNamespace(string $prefix): ?string |
51
|
|
|
{ |
52
|
19 |
|
foreach ($this->namespaces as $p => $ns) { |
53
|
19 |
|
if ($prefix == $p) { |
54
|
19 |
|
return $ns; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get prefix by namespace. |
63
|
|
|
*/ |
64
|
|
|
public function getPrefix(string $namespace): ?string |
65
|
|
|
{ |
66
|
|
|
foreach ($this->namespaces as $prefix => $ns) { |
67
|
|
|
if ($namespace == $ns) { |
68
|
|
|
return $prefix; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return null; |
73
|
|
|
} |
74
|
|
|
|
75
|
23 |
|
public function hasPrefix(string $prefix): bool |
76
|
|
|
{ |
77
|
23 |
|
return true === isset($this->namespaces[$prefix]); |
78
|
|
|
} |
79
|
|
|
|
80
|
12 |
|
public function setPrefix(string $prefix, string $namespace): void |
81
|
|
|
{ |
82
|
12 |
|
$this->namespaces[$prefix] = $namespace; |
83
|
12 |
|
} |
84
|
|
|
} |
85
|
|
|
|