Configure and use custom document loaders
masterDocument loaders are responsible for fetching remote contexts or documents. You can manage them in two ways:
1. Set a global default loader
Use jsonld_set_document_loader($loader_name) to set a global loader for all subsequent calls.
- To force HTTPS-only loading:
jsonld_set_document_loader('jsonld_default_secure_document_loader'); - To set a custom function:
jsonld_set_document_loader('my_custom_doc_loader');
2. Use a per-call loader
Pass a documentLoader key in the options array to a specific function call to avoid modifying the global state.
Note on Custom Loaders: A custom loader should return a RemoteDocument object with properties: contextUrl, document, and documentUrl.
// Per-call custom loader example
$compacted = jsonld_compact($foo, 'http://example.com/mycontext', array(
'documentLoader' => 'mock_load'
));