Compare commits
64 commits
Author | SHA1 | Date | |
---|---|---|---|
1f33c8766b | |||
f52f3f322b | |||
8d1d421b1d | |||
43397ed81c | |||
3249d1f595 | |||
dafc68dc1e | |||
5f6ea87b26 | |||
e37882011f | |||
ca3916d10d | |||
f62652abff | |||
ccbd3d6bc4 | |||
7b779b2b53 | |||
a9ac64daf0 | |||
23cd99e8fb | |||
|
56b01d779d | ||
|
38b07bbe59 | ||
|
dc1bd23f0e | ||
|
3433a01a65 | ||
|
956fb8b790 | ||
|
81b072b438 | ||
|
6b5fba05e5 | ||
|
9759c9340d | ||
|
1abb809e8e | ||
|
b16d43aa74 | ||
|
d832d72b09 | ||
|
e98b8f61ba | ||
|
c63a5961fb | ||
|
57b3279718 | ||
|
e08fe87860 | ||
|
51a0635c61 | ||
|
eb4b344049 | ||
|
2927e09639 | ||
|
3330605897 | ||
|
16155eab6a | ||
|
989c394690 | ||
|
f23d0eb51e | ||
|
e599042c7d | ||
|
95a9945fc2 | ||
|
7535f05755 | ||
|
0cbff8c600 | ||
|
aba9709907 | ||
|
0b0442696d | ||
|
2314cfe0d1 | ||
|
906ad1d805 | ||
|
362a8cb387 | ||
|
e06d20062a | ||
|
b22dbbf285 | ||
|
b13749ed03 | ||
|
7be06f2ee2 | ||
|
237a405175 | ||
|
daed05a54b | ||
|
f252a5281c | ||
|
b80e4b80a5 | ||
|
1a9c6bffdd | ||
|
fed40914c8 | ||
|
bf504a1506 | ||
|
deb6afeac5 | ||
|
ea516341be | ||
|
d4ae67899d | ||
|
8fb6a75e67 | ||
|
8ca3291bc0 | ||
|
d071be64f1 | ||
|
3402d51dff | ||
|
ba16da5b9f |
5 changed files with 6568 additions and 6026 deletions
14
.travis.yml
14
.travis.yml
|
@ -1,14 +0,0 @@
|
||||||
language: php
|
|
||||||
php:
|
|
||||||
- 5.5
|
|
||||||
- 5.4
|
|
||||||
- 5.3
|
|
||||||
# download test suite and run tests... submodule? meta testing project with
|
|
||||||
# all of the reference implementations?
|
|
||||||
script:
|
|
||||||
- git clone https://github.com/json-ld/json-ld.org.git spec
|
|
||||||
- phpunit test.php -d spec/test-suite
|
|
||||||
notifications:
|
|
||||||
email:
|
|
||||||
on_success: change
|
|
||||||
on_failure: change
|
|
114
README.md
114
README.md
|
@ -1,27 +1,29 @@
|
||||||
|
php-json-ld
|
||||||
|
===========
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
JSON, as specified in RFC4627, is a simple language for representing
|
This library is an implementation of the [JSON-LD][] specification in [PHP][].
|
||||||
|
|
||||||
|
JSON, as specified in [RFC7159][], is a simple language for representing
|
||||||
objects on the Web. Linked Data is a way of describing content across
|
objects on the Web. Linked Data is a way of describing content across
|
||||||
different documents or Web sites. Web resources are described using
|
different documents or Web sites. Web resources are described using
|
||||||
IRIs, and typically are dereferencable entities that may be used to find
|
IRIs, and typically are dereferencable entities that may be used to find
|
||||||
more information, creating a "Web of Knowledge". JSON-LD is intended to
|
more information, creating a "Web of Knowledge". [JSON-LD][] is intended
|
||||||
be a simple publishing method for expressing not only Linked Data in
|
to be a simple publishing method for expressing not only Linked Data in
|
||||||
JSON, but for adding semantics to existing JSON.
|
JSON, but for adding semantics to existing JSON.
|
||||||
|
|
||||||
This library is an implementation of the [JSON-LD] specification
|
|
||||||
in [PHP].
|
|
||||||
|
|
||||||
JSON-LD is designed as a light-weight syntax that can be used to express
|
JSON-LD is designed as a light-weight syntax that can be used to express
|
||||||
Linked Data. It is primarily intended to be a way to express Linked Data
|
Linked Data. It is primarily intended to be a way to express Linked Data
|
||||||
in Javascript and other Web-based programming environments. It is also
|
in JavaScript and other Web-based programming environments. It is also
|
||||||
useful when building interoperable Web Services and when storing Linked
|
useful when building interoperable Web Services and when storing Linked
|
||||||
Data in JSON-based document storage engines. It is practical and
|
Data in JSON-based document storage engines. It is practical and
|
||||||
designed to be as simple as possible, utilizing the large number of JSON
|
designed to be as simple as possible, utilizing the large number of JSON
|
||||||
parsers and existing code that is in use today. It is designed to be
|
parsers and existing code that is in use today. It is designed to be
|
||||||
able to express key-value pairs, RDF data, RDFa [RDFA-CORE] data,
|
able to express key-value pairs, RDF data, [RDFa][] data,
|
||||||
Microformats [MICROFORMATS] data, and Microdata [MICRODATA]. That is, it
|
[Microformats][] data, and [Microdata][]. That is, it supports every
|
||||||
supports every major Web-based structured data model in use today.
|
major Web-based structured data model in use today.
|
||||||
|
|
||||||
The syntax does not require many applications to change their JSON, but
|
The syntax does not require many applications to change their JSON, but
|
||||||
easily add meaning by adding context in a way that is either in-band or
|
easily add meaning by adding context in a way that is either in-band or
|
||||||
|
@ -88,40 +90,92 @@ $flattened = jsonld_flatten($doc);
|
||||||
$framed = jsonld_frame($doc, $frame);
|
$framed = jsonld_frame($doc, $frame);
|
||||||
// document transformed into a particular tree structure per the given frame
|
// document transformed into a particular tree structure per the given frame
|
||||||
|
|
||||||
// normalize a document
|
// normalize a document using the RDF Dataset Normalization Algorithm
|
||||||
$normalized = jsonld_normalize($doc, array('format' => 'application/nquads'));
|
// (URDNA2015), see: http://json-ld.github.io/normalization/spec/
|
||||||
|
$normalized = jsonld_normalize(
|
||||||
|
$doc, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads'));
|
||||||
// normalized is a string that is a canonical representation of the document
|
// normalized is a string that is a canonical representation of the document
|
||||||
// that can be used for hashing
|
// that can be used for hashing, comparison, etc.
|
||||||
|
|
||||||
|
// force HTTPS-only context loading:
|
||||||
|
// use built-in secure document loader
|
||||||
|
jsonld_set_document_loader('jsonld_default_secure_document_loader');
|
||||||
|
|
||||||
|
// set a default custom document loader
|
||||||
|
jsonld_set_document_loader('my_custom_doc_loader');
|
||||||
|
|
||||||
|
// a custom loader that demonstrates using a simple in-memory mock for
|
||||||
|
// certain contexts before falling back to the default loader
|
||||||
|
// note: if you want to set this loader as the new default, you'll need to
|
||||||
|
// store the previous default in another variable first and access that inside
|
||||||
|
// the loader
|
||||||
|
global $mocks;
|
||||||
|
$mocks = array('http://example.com/mycontext' => (object)array(
|
||||||
|
'hombre' => 'http://schema.org/name'));
|
||||||
|
function mock_load($url) {
|
||||||
|
global $jsonld_default_load_document, $mocks;
|
||||||
|
if(isset($mocks[$url])) {
|
||||||
|
// return a "RemoteDocument", it has these three properties:
|
||||||
|
return (object)array(
|
||||||
|
'contextUrl' => null,
|
||||||
|
'document' => $mocks[$url],
|
||||||
|
'documentUrl' => $url);
|
||||||
|
}
|
||||||
|
// use default loader
|
||||||
|
return call_user_func($jsonld_default_load_document, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// use the mock loader for just this call, witout modifying the default one
|
||||||
|
$compacted = jsonld_compact($foo, 'http://example.com/mycontext', array(
|
||||||
|
'documentLoader' => 'mock_load'));
|
||||||
|
|
||||||
|
// a custom loader that uses a simplistic in-memory cache (no invalidation)
|
||||||
|
global $cache;
|
||||||
|
$cache = array();
|
||||||
|
function cache_load($url) {
|
||||||
|
global $jsonld_default_load_document, $cache;
|
||||||
|
if(isset($cache[$url])) {
|
||||||
|
return $cache[$url];
|
||||||
|
}
|
||||||
|
// use default loader
|
||||||
|
$doc = call_user_func($jsonld_default_load_document, $url);
|
||||||
|
$cache[$url] = $doc;
|
||||||
|
return $doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use the cache loader for just this call, witout modifying the default one
|
||||||
|
$compacted = jsonld_compact($foo, 'http://schema.org', array(
|
||||||
|
'documentLoader' => 'cache_load'));
|
||||||
```
|
```
|
||||||
|
|
||||||
Commercial Support
|
|
||||||
------------------
|
|
||||||
|
|
||||||
Commercial support for this library is available upon request from
|
|
||||||
Digital Bazaar: support@digitalbazaar.com
|
|
||||||
|
|
||||||
Source
|
Source
|
||||||
------
|
------
|
||||||
|
|
||||||
The source code for the PHP implementation of the JSON-LD API
|
The source code for the PHP implementation of the JSON-LD API is available at:
|
||||||
is available at:
|
|
||||||
|
|
||||||
http://github.com/digitalbazaar/php-json-ld
|
https://git.friendi.ca/friendica/php-json-ld
|
||||||
|
|
||||||
|
Tests
|
||||||
|
-----
|
||||||
|
|
||||||
This library includes a sample testing utility which may be used to verify
|
This library includes a sample testing utility which may be used to verify
|
||||||
that changes to the processor maintain the correct output.
|
that changes to the processor maintain the correct output.
|
||||||
|
|
||||||
To run the sample tests you will need to get the test suite files by cloning
|
To run the sample tests you will need to get the test suite files by cloning
|
||||||
the [json-ld.org repository][json-ld.org] hosted on GitHub.
|
the `json-ld.org` and `normalization` repositories hosted on GitHub:
|
||||||
|
|
||||||
https://github.com/json-ld/json-ld.org
|
- https://github.com/json-ld/json-ld.org
|
||||||
|
- https://github.com/json-ld/normalization
|
||||||
|
|
||||||
Then run the PHPUnit test.php application and point it at the directory
|
Then run the PHPUnit test.php application and point it at the directories
|
||||||
containing the tests.
|
containing the tests:
|
||||||
|
|
||||||
phpunit test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
|
phpunit --group json-ld.org test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
|
||||||
|
phpunit --group normalization test.php -d {PATH_TO_NORMALIZATION/tests}
|
||||||
|
|
||||||
[PHP]: http://php.net
|
|
||||||
[JSON-LD]: http://json-ld.org/
|
[JSON-LD]: http://json-ld.org/
|
||||||
[json-ld.org]: https://github.com/json-ld/json-ld.org
|
[Microdata]: http://www.w3.org/TR/microdata/
|
||||||
|
[Microformats]: http://microformats.org/
|
||||||
|
[PHP]: http://php.net
|
||||||
|
[RDFa]: http://www.w3.org/TR/rdfa-core/
|
||||||
|
[RFC7159]: http://tools.ietf.org/html/rfc7159
|
||||||
|
|
33
composer.json
Normal file
33
composer.json
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"name": "friendica/json-ld",
|
||||||
|
"type": "library",
|
||||||
|
"description": "A JSON-LD Processor and API implementation in PHP.",
|
||||||
|
"keywords": [
|
||||||
|
"JSON",
|
||||||
|
"Linked Data",
|
||||||
|
"JSON-LD",
|
||||||
|
"RDF",
|
||||||
|
"Semantic Web",
|
||||||
|
"jsonld"
|
||||||
|
],
|
||||||
|
"homepage": "https://git.friendi.ca/friendica/php-json-ld",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Digital Bazaar, Inc.",
|
||||||
|
"email": "support@digitalbazaar.com",
|
||||||
|
"homepage": "http://digitalbazaar.com/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Friendica Team",
|
||||||
|
"homepage": "https://friendi.ca/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.4.0",
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": ["jsonld.php"]
|
||||||
|
}
|
||||||
|
}
|
11130
jsonld.php
11130
jsonld.php
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue