1 | <?php |
||
53 | class Context |
||
54 | { |
||
55 | /** |
||
56 | * Default vocabularies and their prefixes |
||
57 | * |
||
58 | * @var array |
||
59 | * @see https://www.w3.org/2011/rdfa-context/rdfa-1.1 |
||
60 | * @link https://www.w3.org/2013/json-ld-context/rdfa11 |
||
61 | */ |
||
62 | protected static $defaultVocabularies = [ |
||
63 | 'cat' => 'http://www.w3.org/ns/dcat#', |
||
64 | 'qb' => 'http://purl.org/linked-data/cube#', |
||
65 | 'grddl' => 'http://www.w3.org/2003/g/data-view#', |
||
66 | 'ma' => 'http://www.w3.org/ns/ma-ont#', |
||
67 | 'owl' => 'http://www.w3.org/2002/07/owl#', |
||
68 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
69 | 'rdfa' => 'http://www.w3.org/ns/rdfa#', |
||
70 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
||
71 | 'rif' => 'http://www.w3.org/2007/rif#', |
||
72 | 'rr' => 'http://www.w3.org/ns/r2rml#', |
||
73 | 'skos' => 'http://www.w3.org/2004/02/skos/core#', |
||
74 | 'skosxl' => 'http://www.w3.org/2008/05/skos-xl#', |
||
75 | 'wdr' => 'http://www.w3.org/2007/05/powder#', |
||
76 | 'void' => 'http://rdfs.org/ns/void#', |
||
77 | 'wdrs' => 'http://www.w3.org/2007/05/powder-s#', |
||
78 | 'xhv' => 'http://www.w3.org/1999/xhtml/vocab#', |
||
79 | 'xml' => 'http://www.w3.org/XML/1998/namespace', |
||
80 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
||
81 | 'prov' => 'http://www.w3.org/ns/prov#', |
||
82 | 'sd' => 'http://www.w3.org/ns/sparql-service-description#', |
||
83 | 'org' => 'http://www.w3.org/ns/org#', |
||
84 | 'gldp' => 'http://www.w3.org/ns/people#', |
||
85 | 'cnt' => 'http://www.w3.org/2008/content#', |
||
86 | 'dcat' => 'http://www.w3.org/ns/dcat#', |
||
87 | 'earl' => 'http://www.w3.org/ns/earl#', |
||
88 | 'ht' => 'http://www.w3.org/2006/http#', |
||
89 | 'ptr' => 'http://www.w3.org/2009/pointers#', |
||
90 | 'cc' => 'http://creativecommons.org/ns#', |
||
91 | 'ctag' => 'http://commontag.org/ns#', |
||
92 | 'dc' => 'http://purl.org/dc/terms/', |
||
93 | 'dc11' => 'http://purl.org/dc/elements/1.1/', |
||
94 | 'dcterms' => 'http://purl.org/dc/terms/', |
||
95 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
||
96 | 'gr' => 'http://purl.org/goodrelations/v1#', |
||
97 | 'ical' => 'http://www.w3.org/2002/12/cal/icaltzd#', |
||
98 | 'og' => 'http://ogp.me/ns#', |
||
99 | 'rev' => 'http://purl.org/stuff/rev#', |
||
100 | 'sioc' => 'http://rdfs.org/sioc/ns#', |
||
101 | 'v' => 'http://rdf.data-vocabulary.org/#', |
||
102 | 'vcard' => 'http://www.w3.org/2006/vcard/ns#', |
||
103 | 'schema' => 'http://schema.org/', |
||
104 | 'describedby' => 'http://www.w3.org/2007/05/powder-s#describedby', |
||
105 | 'license' => 'http://www.w3.org/1999/xhtml/vocab#license', |
||
106 | 'role' => 'http://www.w3.org/1999/xhtml/vocab#role' |
||
107 | ]; |
||
108 | |||
109 | /** |
||
110 | * Registered vocabularies |
||
111 | * |
||
112 | * @var array |
||
113 | */ |
||
114 | protected $vocabularies; |
||
115 | |||
116 | /** |
||
117 | * Current default vocabulary |
||
118 | * |
||
119 | * @var VocabularyInterface |
||
120 | */ |
||
121 | protected $defaultVocabulary = null; |
||
122 | |||
123 | /** |
||
124 | * Parent thing |
||
125 | * |
||
126 | * @var ThingInterface |
||
127 | */ |
||
128 | protected $parentThing; |
||
129 | |||
130 | /** |
||
131 | * Context constructor |
||
132 | */ |
||
133 | 17 | public function __construct() |
|
138 | |||
139 | /** |
||
140 | * Return the registered child things |
||
141 | * |
||
142 | * @return ThingInterface[] Child things |
||
143 | */ |
||
144 | 5 | public function getChildren() |
|
148 | |||
149 | /** |
||
150 | * Register a vocabulary and its prefix |
||
151 | * |
||
152 | * @param string $prefix Vocabulary prefix |
||
153 | * @param string $uri Vocabulary URI |
||
154 | * @return Context New context |
||
155 | * |
||
156 | */ |
||
157 | 9 | public function registerVocabulary($prefix, $uri) |
|
171 | |||
172 | /** |
||
173 | * Validata a vocabulary prefix |
||
174 | * |
||
175 | * @param string $prefix Vocabulary prefix |
||
176 | * @return string Valid vocabulary prefix |
||
177 | * @throws RuntimeException If the vocabulary prefix is invalid |
||
178 | */ |
||
179 | 11 | protected static function validateVocabPrefix($prefix) |
|
193 | |||
194 | /** |
||
195 | * Return a particular vocabulary |
||
196 | * |
||
197 | * @param string $prefix Vocabulary Prefix |
||
198 | * @return VocabularyInterface Vocabulary |
||
199 | * @throws OutOfBoundsException If the prefix has not been registered |
||
200 | */ |
||
201 | 7 | public function getVocabulary($prefix) |
|
215 | |||
216 | /** |
||
217 | * Return whether a particular vocabulary prefix has been registered |
||
218 | * |
||
219 | * @param string $prefix Vocabulary prefix |
||
220 | * @return bool Whether the prefix has been registered |
||
221 | */ |
||
222 | 2 | public function hasVocabulary($prefix) |
|
226 | |||
227 | /** |
||
228 | * Return the current default vocabulary |
||
229 | * |
||
230 | * @return VocabularyInterface Current default vocabulary |
||
231 | */ |
||
232 | 7 | public function getDefaultVocabulary() |
|
236 | |||
237 | /** |
||
238 | * Set the default vocabulary by URI |
||
239 | * |
||
240 | * @param VocabularyInterface $vocabulary Current default vocabulary |
||
241 | * @return Context Self reference |
||
242 | */ |
||
243 | 7 | public function setDefaultVocabulary(VocabularyInterface $vocabulary) |
|
254 | |||
255 | /** |
||
256 | * Get the current parent thing |
||
257 | * |
||
258 | * @return ThingInterface|null Parent thing |
||
259 | */ |
||
260 | 5 | public function getParentThing() |
|
264 | |||
265 | /** |
||
266 | * Set the parent thing |
||
267 | * |
||
268 | * @param ThingInterface $parentThing Parent thing |
||
269 | * @return Context |
||
270 | */ |
||
271 | 6 | public function setParentThing(ThingInterface $parentThing) |
|
282 | |||
283 | /** |
||
284 | * Add a child thing |
||
285 | * |
||
286 | * @param ThingInterface $thing Child thing |
||
287 | * @return Context Self reference |
||
288 | */ |
||
289 | 5 | public function addChild(ThingInterface $thing) |
|
294 | } |
||
295 |