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 | * @return RemoteDocument|null Cached document |
||
86 | */ |
||
87 | 1 | public function getDocument($url) |
|
98 | |||
99 | /** |
||
100 | * Create a cache hash |
||
101 | * |
||
102 | * @param string $str String |
||
103 | * @param string $slot Slot |
||
104 | * @return string URL hash |
||
105 | */ |
||
106 | 1 | protected function getCacheHash($str, $slot) |
|
110 | |||
111 | /** |
||
112 | * Cache a document |
||
113 | * |
||
114 | * @param string $url URL |
||
115 | * @param RemoteDocument $document Document |
||
116 | * @return RemoteDocument Document |
||
117 | */ |
||
118 | 1 | public function setDocument($url, RemoteDocument $document) |
|
134 | |||
135 | /** |
||
136 | * Process a context vocabulary |
||
137 | * |
||
138 | * @param array $context Context |
||
139 | */ |
||
140 | 1 | protected function processContext(array $context) |
|
160 | |||
161 | /** |
||
162 | * Test if a vocabulary name or definition is a reserved term |
||
163 | * |
||
164 | * @param string $name Name |
||
165 | * @param string $definition Definition |
||
166 | * @return boolean Is reserved term |
||
167 | */ |
||
168 | 1 | protected function isReservedTokens($name, $definition) |
|
172 | |||
173 | /** |
||
174 | * Process a prefix / vocabulary term |
||
175 | * |
||
176 | * @param string $name Prefix name |
||
177 | * @param string|\stdClass $definition Definition |
||
178 | * @param array $prefices Prefix register |
||
179 | * @param array $vocabularies Vocabulary register |
||
180 | */ |
||
181 | 1 | protected function processPrefixVocabularyTerm($name, $definition, array &$prefices, array &$vocabularies) |
|
192 | |||
193 | /** |
||
194 | * Test whether this is a prefix and vocabulary definition |
||
195 | * |
||
196 | * @param string $name Prefix name |
||
197 | * @param string|\stdClass $definition Definition |
||
198 | * @param array $prefices Prefix register |
||
199 | * @return bool Is a prefix and vocabulary definition |
||
200 | */ |
||
201 | 1 | protected function isPrefix($name, $definition, array &$prefices) |
|
205 | |||
206 | /** |
||
207 | * Process a vocabulary prefix |
||
208 | * |
||
209 | * @param string $name Prefix name |
||
210 | * @param string $definition Prefix definition |
||
211 | * @param array $prefices Prefix register |
||
212 | * @param array $vocabularies Vocabulary register |
||
213 | */ |
||
214 | 1 | protected function processPrefix($name, $definition, array &$prefices, array &$vocabularies) |
|
223 | |||
224 | /** |
||
225 | * Test whether this is a term definition |
||
226 | * |
||
227 | * @param string|\stdClass $definition Definition |
||
228 | * @return bool Is a term definition |
||
229 | */ |
||
230 | 1 | protected function isTerm($definition) |
|
234 | |||
235 | /** |
||
236 | * Process a vocabulary term |
||
237 | * |
||
238 | * @param \stdClass $definition Term definition |
||
239 | * @param array $prefices Prefix register |
||
240 | * @param array $vocabularies Vocabulary register |
||
241 | */ |
||
242 | 1 | protected function processVocabularyTerm($definition, array &$prefices, array &$vocabularies) |
|
251 | |||
252 | /** |
||
253 | * Create an IRI from a name considering the known vocabularies |
||
254 | * |
||
255 | * @param string $name Name |
||
256 | * @return \stdClass IRI |
||
257 | */ |
||
258 | 2 | public function expandIRI($name) |
|
270 | |||
271 | /** |
||
272 | * Match a name with the known vocabularies |
||
273 | * |
||
274 | * @param string $name Name |
||
275 | * @param array $vocabularies Vocabularies |
||
276 | * @param \stdClass $iri IRI |
||
277 | */ |
||
278 | 1 | protected function matchVocabularies($name, array $vocabularies, &$iri) |
|
292 | } |
||
293 |