Compare commits
No commits in common. "master" and "0.4.3" have entirely different histories.
5 changed files with 6088 additions and 6566 deletions
14
.travis.yml
Normal file
14
.travis.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
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,29 +1,27 @@
|
||||||
php-json-ld
|
|
||||||
===========
|
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
This library is an implementation of the [JSON-LD][] specification in [PHP][].
|
JSON, as specified in RFC4627, is a simple language for representing
|
||||||
|
|
||||||
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
|
more information, creating a "Web of Knowledge". JSON-LD is intended to
|
||||||
to be a simple publishing method for expressing not only Linked Data in
|
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][] data,
|
able to express key-value pairs, RDF data, RDFa [RDFA-CORE] data,
|
||||||
[Microformats][] data, and [Microdata][]. That is, it supports every
|
Microformats [MICROFORMATS] data, and Microdata [MICRODATA]. That is, it
|
||||||
major Web-based structured data model in use today.
|
supports every 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
|
||||||
|
@ -90,92 +88,40 @@ $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 using the RDF Dataset Normalization Algorithm
|
// normalize a document
|
||||||
// (URDNA2015), see: http://json-ld.github.io/normalization/spec/
|
$normalized = jsonld_normalize($doc, array('format' => 'application/nquads'));
|
||||||
$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, comparison, etc.
|
// that can be used for hashing
|
||||||
|
|
||||||
// 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 is available at:
|
The source code for the PHP implementation of the JSON-LD API
|
||||||
|
is available at:
|
||||||
|
|
||||||
https://git.friendi.ca/friendica/php-json-ld
|
http://github.com/digitalbazaar/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` and `normalization` repositories hosted on GitHub:
|
the [json-ld.org repository][json-ld.org] 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 directories
|
Then run the PHPUnit test.php application and point it at the directory
|
||||||
containing the tests:
|
containing the tests.
|
||||||
|
|
||||||
phpunit --group json-ld.org test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
|
phpunit test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
|
||||||
phpunit --group normalization test.php -d {PATH_TO_NORMALIZATION/tests}
|
|
||||||
|
|
||||||
[JSON-LD]: http://json-ld.org/
|
|
||||||
[Microdata]: http://www.w3.org/TR/microdata/
|
|
||||||
[Microformats]: http://microformats.org/
|
|
||||||
[PHP]: http://php.net
|
[PHP]: http://php.net
|
||||||
[RDFa]: http://www.w3.org/TR/rdfa-core/
|
[JSON-LD]: http://json-ld.org/
|
||||||
[RFC7159]: http://tools.ietf.org/html/rfc7159
|
[json-ld.org]: https://github.com/json-ld/json-ld.org
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
{
|
|
||||||
"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"]
|
|
||||||
}
|
|
||||||
}
|
|
11190
jsonld.php
11190
jsonld.php
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue