1 | <?php |
||
48 | class VocabularyCache |
||
49 | { |
||
50 | /** |
||
51 | * Document cache slot |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | const SLOT_DOC = 'jsonld.doc'; |
||
56 | /** |
||
57 | * Vocabulary cache slot |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | const SLOT_VOCABS = 'jsonld.vocabs'; |
||
62 | /** |
||
63 | * Documents |
||
64 | * |
||
65 | * @var RemoteDocument[] |
||
66 | */ |
||
67 | protected $documents = []; |
||
68 | /** |
||
69 | * Vocabularies |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $vocabularies = []; |
||
74 | /** |
||
75 | * Vocabulary prefices |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $prefices = []; |
||
80 | |||
81 | /** |
||
82 | * Return a cached document |
||
83 | * |
||
84 | * @param string $url URL |
||
85 | * |
||
86 | * @return RemoteDocument|null Cached document |
||
87 | */ |
||
88 | 2 | public function getDocument($url) |
|
99 | |||
100 | /** |
||
101 | * Create a cache hash |
||
102 | * |
||
103 | * @param string $str String |
||
104 | * @param string $slot Slot |
||
105 | * |
||
106 | * @return string URL hash |
||
107 | */ |
||
108 | 2 | protected function getCacheHash($str, $slot) |
|
112 | |||
113 | /** |
||
114 | * Cache a document |
||
115 | * |
||
116 | * @param string $url URL |
||
117 | * @param RemoteDocument $document Document |
||
118 | * |
||
119 | * @return RemoteDocument Document |
||
120 | */ |
||
121 | 2 | public function setDocument($url, RemoteDocument $document) |
|
137 | |||
138 | /** |
||
139 | * Process a context vocabulary |
||
140 | * |
||
141 | * @param array $context Context |
||
142 | */ |
||
143 | 2 | protected function processContext(array $context) |
|
163 | |||
164 | /** |
||
165 | * Test if a vocabulary name or definition is a reserved term |
||
166 | * |
||
167 | * @param string $name Name |
||
168 | * @param string $definition Definition |
||
169 | * |
||
170 | * @return boolean Is reserved term |
||
171 | */ |
||
172 | 2 | protected function isReservedTokens($name, $definition) |
|
176 | |||
177 | /** |
||
178 | * Process a prefix / vocabulary term |
||
179 | * |
||
180 | * @param string $name Prefix name |
||
181 | * @param string|\stdClass $definition Definition |
||
182 | * @param array $prefices Prefix register |
||
183 | * @param array $vocabularies Vocabulary register |
||
184 | */ |
||
185 | 2 | protected function processPrefixVocabularyTerm($name, $definition, array &$prefices, array &$vocabularies) |
|
196 | |||
197 | /** |
||
198 | * Test whether this is a prefix and vocabulary definition |
||
199 | * |
||
200 | * @param string $name Prefix name |
||
201 | * @param string|\stdClass $definition Definition |
||
202 | * @param array $prefices Prefix register |
||
203 | * |
||
204 | * @return bool Is a prefix and vocabulary definition |
||
205 | */ |
||
206 | 2 | protected function isPrefix($name, $definition, array &$prefices) |
|
210 | |||
211 | /** |
||
212 | * Process a vocabulary prefix |
||
213 | * |
||
214 | * @param string $name Prefix name |
||
215 | * @param string $definition Prefix definition |
||
216 | * @param array $prefices Prefix register |
||
217 | * @param array $vocabularies Vocabulary register |
||
218 | */ |
||
219 | 2 | protected function processPrefix($name, $definition, array &$prefices, array &$vocabularies) |
|
228 | |||
229 | /** |
||
230 | * Test whether this is a term definition |
||
231 | * |
||
232 | * @param string|\stdClass $definition Definition |
||
233 | * |
||
234 | * @return bool Is a term definition |
||
235 | */ |
||
236 | 2 | protected function isTerm($definition) |
|
240 | |||
241 | /** |
||
242 | * Process a vocabulary term |
||
243 | * |
||
244 | * @param \stdClass $definition Term definition |
||
245 | * @param array $prefices Prefix register |
||
246 | * @param array $vocabularies Vocabulary register |
||
247 | */ |
||
248 | 2 | protected function processVocabularyTerm($definition, array &$prefices, array &$vocabularies) |
|
257 | |||
258 | /** |
||
259 | * Create an IRI from a name considering the known vocabularies |
||
260 | * |
||
261 | * @param string $name Name |
||
262 | * |
||
263 | * @return \stdClass IRI |
||
264 | */ |
||
265 | 4 | public function expandIRI($name) |
|
277 | |||
278 | /** |
||
279 | * Match a name with the known vocabularies |
||
280 | * |
||
281 | * @param string $name Name |
||
282 | * @param array $vocabularies Vocabularies |
||
283 | * @param \stdClass $iri IRI |
||
284 | */ |
||
285 | 3 | protected function matchVocabularies($name, array $vocabularies, &$iri) |
|
300 | } |
||
301 |