1. Go to this page and download the library: Download accredifysg/php-json-ld library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
accredifysg / php-json-ld example snippets
use Accredify\JsonLd\JsonLdProcessor;
use Accredify\JsonLd\Loaders\CachingDocumentLoader;
use Accredify\JsonLd\Loaders\HttpDocumentLoader;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
$loader = new CachingDocumentLoader(
new HttpDocumentLoader(new Client, new HttpFactory),
);
$processor = new JsonLdProcessor($loader);
$expanded = $processor->expand($document);
$compacted = $processor->compact($expanded->toArray(), $context)->toArray();
$nQuads = $processor->toRdf($document)->toNQuads();
use Accredify\JsonLd\Exceptions\DataLossException;
use Accredify\JsonLd\JsonLdOptions;
try {
$nQuads = $processor->toRdf($document, new JsonLdOptions(safe: true))->toNQuads();
} catch (DataLossException $e) {
// e.g. "Safe mode: term 'alumniOf' does not expand to an absolute IRI
// or keyword (invalid property)"
$e->eventCode; // 'invalid property' — jsonld.js-compatible event code
$e->details; // ['term' => 'alumniOf', …] — the dropped datum
}