1 | <?php |
||
48 | class VocabularyCache |
||
49 | { |
||
50 | /** |
||
51 | * Documents |
||
52 | * |
||
53 | * @var RemoteDocument[] |
||
54 | */ |
||
55 | protected $documents = []; |
||
56 | /** |
||
57 | * Vocabularies |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $vocabularies = []; |
||
62 | /** |
||
63 | * Vocabulary prefices |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $prefices = []; |
||
68 | /** |
||
69 | * Document cache slot |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | const SLOT_DOC = 'jsonld.doc'; |
||
74 | /** |
||
75 | * Vocabulary cache slot |
||
76 | * |
||
77 | * @var string |
||
78 | */ |
||
79 | const SLOT_VOCABS = 'jsonld.vocabs'; |
||
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 | * Cache a document |
||
101 | * |
||
102 | * @param string $url URL |
||
103 | * @param RemoteDocument $document Document |
||
104 | * @return RemoteDocument Document |
||
105 | */ |
||
106 | 1 | public function setDocument($url, RemoteDocument $document) |
|
124 | |||
125 | /** |
||
126 | * Process a context vocabulary |
||
127 | * |
||
128 | * @param array $context Context |
||
129 | */ |
||
130 | 1 | protected function processContext(array $context) |
|
150 | |||
151 | /** |
||
152 | * Process a prefix / vocabulary term |
||
153 | * |
||
154 | * @param string $name Prefix name |
||
155 | * @param string|\stdClass $definition Definition |
||
156 | * @param array $prefices Prefix register |
||
157 | * @param array $vocabularies Vocabulary register |
||
158 | */ |
||
159 | 1 | protected function processPrefixVocabularyTerm($name, $definition, array &$prefices, array &$vocabularies) |
|
170 | |||
171 | /** |
||
172 | * Process a vocabulary prefix |
||
173 | * |
||
174 | * @param string $name Prefix name |
||
175 | * @param string $definition Prefix definition |
||
176 | * @param array $prefices Prefix register |
||
177 | * @param array $vocabularies Vocabulary register |
||
178 | */ |
||
179 | 1 | protected function processPrefix($name, $definition, array &$prefices, array &$vocabularies) |
|
188 | |||
189 | /** |
||
190 | * Process a vocabulary term |
||
191 | * |
||
192 | * @param \stdClass $definition Term definition |
||
193 | * @param array $prefices Prefix register |
||
194 | * @param array $vocabularies Vocabulary register |
||
195 | */ |
||
196 | 1 | protected function processVocabularyTerm($definition, array &$prefices, array &$vocabularies) |
|
205 | |||
206 | /** |
||
207 | * Create an IRI from a name considering the known vocabularies |
||
208 | * |
||
209 | * @param string $name Name |
||
210 | * @return \stdClass IRI |
||
211 | */ |
||
212 | 2 | public function expandIRI($name) |
|
230 | |||
231 | /** |
||
232 | * Create a cache hash |
||
233 | * |
||
234 | * @param string $str String |
||
235 | * @param string $slot Slot |
||
236 | * @return string URL hash |
||
237 | */ |
||
238 | 1 | protected function getCacheHash($str, $slot) |
|
242 | } |
||
243 |