-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate-id-properties.php
More file actions
31 lines (21 loc) · 1.04 KB
/
generate-id-properties.php
File metadata and controls
31 lines (21 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* This script generates a list of schema.org properties that map to a URL according to schema.org's JSON-LD context.
* The resulting id-properties.php file is required by brick/structured-data for now, because it does not have a
* compliant JSON-LD context parser yet. When it does, we'll be able to get rid of this list, and ship this library
* with its own jsonldcontext.jsonld file and pass this file to the library directly.
*/
declare(strict_types=1);
use Brick\VarExporter\VarExporter;
require 'vendor/autoload.php';
$schema = json_decode(file_get_contents(__DIR__ . '/jsonldcontext.jsonld'), flags: JSON_THROW_ON_ERROR);
$ids = [];
foreach ($schema->{'@context'} as $key => $value) {
if (is_object($value) && isset($value->{'@type'}) && $value->{'@type'} === '@id') {
$id = $value->{'@id'};
$id = preg_replace('/^schema\:/', 'http://schema.org/', $id);
$ids[] = $id;
}
}
$php = '<?php ' . VarExporter::export($ids, VarExporter::ADD_RETURN);
file_put_contents(__DIR__ . '/data/id-properties.php', $php);