Compare commits

..

No commits in common. "master" and "0.3.7" have entirely different histories.

5 changed files with 6026 additions and 6568 deletions

14
.travis.yml Normal file
View 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
View file

@ -1,29 +1,27 @@
php-json-ld
===========
Introduction
------------
This library is an implementation of the [JSON-LD][] specification in [PHP][].
JSON, as specified in [RFC7159][], is a simple language for representing
JSON, as specified in RFC4627, is a simple language for representing
objects on the Web. Linked Data is a way of describing content across
different documents or Web sites. Web resources are described using
IRIs, and typically are dereferencable entities that may be used to find
more information, creating a "Web of Knowledge". [JSON-LD][] is intended
to be a simple publishing method for expressing not only Linked Data in
more information, creating a "Web of Knowledge". JSON-LD is intended to
be a simple publishing method for expressing not only Linked Data in
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
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
Data in JSON-based document storage engines. It is practical and
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
able to express key-value pairs, RDF data, [RDFa][] data,
[Microformats][] data, and [Microdata][]. That is, it supports every
major Web-based structured data model in use today.
able to express key-value pairs, RDF data, RDFa [RDFA-CORE] data,
Microformats [MICROFORMATS] data, and Microdata [MICRODATA]. That is, it
supports every major Web-based structured data model in use today.
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
@ -90,92 +88,40 @@ $flattened = jsonld_flatten($doc);
$framed = jsonld_frame($doc, $frame);
// document transformed into a particular tree structure per the given frame
// normalize a document using the RDF Dataset Normalization Algorithm
// (URDNA2015), see: http://json-ld.github.io/normalization/spec/
$normalized = jsonld_normalize(
$doc, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads'));
// normalize a document
$normalized = jsonld_normalize($doc, array('format' => 'application/nquads'));
// normalized is a string that is a canonical representation of the document
// 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'));
// that can be used for hashing
```
Commercial Support
------------------
Commercial support for this library is available upon request from
Digital Bazaar: support@digitalbazaar.com
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
Tests
-----
http://github.com/digitalbazaar/php-json-ld
This library includes a sample testing utility which may be used to verify
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
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/normalization
https://github.com/json-ld/json-ld.org
Then run the PHPUnit test.php application and point it at the directories
containing the tests:
Then run the PHPUnit test.php application and point it at the directory
containing the tests.
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}
phpunit test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
[JSON-LD]: http://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
[JSON-LD]: http://json-ld.org/
[json-ld.org]: https://github.com/json-ld/json-ld.org

View file

@ -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"]
}
}

11130
jsonld.php

File diff suppressed because it is too large Load diff

1303
test.php

File diff suppressed because it is too large Load diff