@@ -98,6 +98,39 @@ $framed = jsonld_frame($doc, $frame);
98
98
$normalized = jsonld_normalize($doc, array('format' => 'application/nquads'));
99
99
// normalized is a string that is a canonical representation of the document
100
100
// that can be used for hashing
101
+
102
+ // force HTTPS-only context loading:
103
+ // use built-in secure document loader
104
+ jsonld_set_document_loader('jsonld_default_secure_document_loader');
105
+
106
+ // set a default custom document loader
107
+ jsonld_set_document_loader('my_custom_doc_loader');
108
+
109
+ // a custom loader that demonstrates checking a simple in-memory cache
110
+ // before falling back to the default loader
111
+ // note: if you want to set this loader as the new default, you'll need to
112
+ // store the previous default in another variable first and access that inside
113
+ // the loader
114
+ global $cache;
115
+ $cache = array('http://example.com/mycontext' => (object)array(
116
+ 'hombre' => 'http://schema.org/name'));
117
+
118
+ function custom_load($url) {
119
+ global $jsonld_default_load_document, $cache;
120
+ if(isset($cache[$url])) {
121
+ // return a "RemoteDocument", it has these three properties:
122
+ return (object)array(
123
+ 'contextUrl' => null,
124
+ 'document' => $cache[$url],
125
+ 'documentUrl' => $url);
126
+ }
127
+ // use default loader
128
+ return call_user_func($jsonld_default_load_document, $url);
129
+ }
130
+
131
+ // use the custom loader for just this call, witout modifying the default one
132
+ $compacted = jsonld_compact($foo, 'http://example.com/mycontext', array(
133
+ 'documentLoader' => 'custom_load'));
101
134
```
102
135
103
136
Commercial Support
0 commit comments