Commit d5eb64ce authored by webchick's avatar webchick

Issue #2401109 by larowlan, kim.pepper: Update EasyRdf to latest stable

parent 451bf657
......@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "57cb0f99786ec791d5e89578b7ed4602",
"hash": "9f93d739d3134a5fb76d650043b3ba89",
"packages": [
{
"name": "doctrine/annotations",
......@@ -460,31 +460,30 @@
},
{
"name": "easyrdf/easyrdf",
"version": "0.8.0",
"version": "0.9.0",
"source": {
"type": "git",
"url": "https://github.com/njh/easyrdf.git",
"reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2"
"reference": "bb9fd99768d23af0c5b7b55cec5baddc201272b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/njh/easyrdf/zipball/3e43ab7274004e9f4192e06b9fc147781e1f85c2",
"reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2",
"url": "https://api.github.com/repos/njh/easyrdf/zipball/bb9fd99768d23af0c5b7b55cec5baddc201272b8",
"reference": "bb9fd99768d23af0c5b7b55cec5baddc201272b8",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"ext-pcre": "*",
"php": ">=5.2.8"
},
"replace": {
"njh/easyrdf": "self.version"
},
"require-dev": {
"phpunit/phpunit": ">=3.5.15",
"sami/sami": "dev-master",
"squizlabs/php_codesniffer": ">=1.4.3"
"phpunit/phpunit": "~3.5",
"sami/sami": "~1.4",
"squizlabs/php_codesniffer": "~1.4.3"
},
"suggest": {
"ml/json-ld": "dev-master"
"ml/json-ld": "~1.0"
},
"type": "library",
"autoload": {
......@@ -502,6 +501,11 @@
"email": "njh@aelius.com",
"homepage": "http://www.aelius.com/njh/",
"role": "Developer"
},
{
"name": "Alexey Zakhlestin",
"email": "indeyets@gmail.com",
"role": "Developer"
}
],
"description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.",
......@@ -514,7 +518,7 @@
"rdfa",
"sparql"
],
"time": "2013-12-30 22:31:37"
"time": "2014-11-07 18:02:16"
},
{
"name": "egulias/email-validator",
......@@ -2575,6 +2579,7 @@
"phpunit/phpunit-mock-objects": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.4.5"
},
......
......@@ -59,6 +59,7 @@ public function getPrefixes()
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
......
......@@ -409,66 +409,6 @@
"spl"
]
},
{
"name": "easyrdf/easyrdf",
"version": "0.8.0",
"version_normalized": "0.8.0.0",
"source": {
"type": "git",
"url": "https://github.com/njh/easyrdf.git",
"reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/njh/easyrdf/zipball/3e43ab7274004e9f4192e06b9fc147781e1f85c2",
"reference": "3e43ab7274004e9f4192e06b9fc147781e1f85c2",
"shasum": ""
},
"require": {
"php": ">=5.2.8"
},
"replace": {
"njh/easyrdf": "self.version"
},
"require-dev": {
"phpunit/phpunit": ">=3.5.15",
"sami/sami": "dev-master",
"squizlabs/php_codesniffer": ">=1.4.3"
},
"suggest": {
"ml/json-ld": "dev-master"
},
"time": "2013-12-30 22:31:37",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"EasyRdf_": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nicholas Humfrey",
"email": "njh@aelius.com",
"homepage": "http://www.aelius.com/njh/",
"role": "Developer"
}
],
"description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.",
"homepage": "http://www.easyrdf.org/",
"keywords": [
"Linked Data",
"RDF",
"Semantic Web",
"Turtle",
"rdfa",
"sparql"
]
},
{
"name": "react/promise",
"version": "v2.1.0",
......@@ -2652,5 +2592,69 @@
],
"description": "Symfony Process Component",
"homepage": "http://symfony.com"
},
{
"name": "easyrdf/easyrdf",
"version": "0.9.0",
"version_normalized": "0.9.0.0",
"source": {
"type": "git",
"url": "https://github.com/njh/easyrdf.git",
"reference": "bb9fd99768d23af0c5b7b55cec5baddc201272b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/njh/easyrdf/zipball/bb9fd99768d23af0c5b7b55cec5baddc201272b8",
"reference": "bb9fd99768d23af0c5b7b55cec5baddc201272b8",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"ext-pcre": "*",
"php": ">=5.2.8"
},
"require-dev": {
"phpunit/phpunit": "~3.5",
"sami/sami": "~1.4",
"squizlabs/php_codesniffer": "~1.4.3"
},
"suggest": {
"ml/json-ld": "~1.0"
},
"time": "2014-11-07 18:02:16",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"EasyRdf_": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nicholas Humfrey",
"email": "njh@aelius.com",
"homepage": "http://www.aelius.com/njh/",
"role": "Developer"
},
{
"name": "Alexey Zakhlestin",
"email": "indeyets@gmail.com",
"role": "Developer"
}
],
"description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.",
"homepage": "http://www.easyrdf.org/",
"keywords": [
"Linked Data",
"RDF",
"Semantic Web",
"Turtle",
"rdfa",
"sparql"
]
}
]
EasyRdf 0.9.0
=============
* code-style fix
EasyRdf 0.9.0-rc.4
==================
* fixed compatibility with php < 5.4.8 (see issue #212)
* tweaked unit-tests
EasyRdf 0.9.0-rc.3
==================
* fixed documentation generation
EasyRdf 0.9.0-rc.2
==================
* tweaked unit-tests
EasyRdf 0.9.0-rc.1
==================
Major new features
------------------
* Framing support in `EasyRdf_Serialiser_JsonLd`
* JSON-LD Parser
API changes
-----------
* `EasyRdf_Literal_Decimal` returns strings, instead of floats to avoid losing precision (see issue #178)
* `EasyRdf_Literal_Decimal` requires input-strings which conform to `xs:decimal` format
* `EasyRdf_GraphStore` supports operations over default graph now
* `EasyRdf_Literal` typed as `xs:double` is used for PHP-floats instead of `EasyRdf_Literal_Decimal`
* Exceptions thrown from `EasyRdf_Graph::resource()` use different message-texts now (see issue #159)
Enhancements
------------
* Synced list of default namespaces against [RDFa Core Initial Context](http://www.w3.org/2011/rdfa-context/rdfa-1.1) rev.2014-01-17
* Added support for empty prefixes (see issue #183)
* `EasyRdf_Graph::newAndLoad` throws `EasyRdf_Http_Exception` in case of failure, which gives access to status and response-body. (see issue #149)
* `EasyRdf_Graph` and `EasyRdf_Resource` have 'typesAsResources()' methods now
Bug Fixes
---------
* Fix for Turtle serialisation of FALSE (see issue #179)
* Fix for edge-case in RDF/XML serialisation (see issue #186)
* SPARQL-queries against endpoints which have query-params in their URL (see issue #184)
* Float values are properly handled if locale with "other" separator is active
* Fixed parsing of Turtle-documents with higher utf-8 characters (see issue #195)
* Namespace-prefixes are compliant with RDFXML QName spec (see issue #185)
* `EasyRdf_Namespace` won't generate "short" names with "/" in them anymore (see issue #115)
* `EasyRdf_Parser_RdfXml` respects "base" specified for the document (see issue #157)
* HTML documents are correctly detected now, not as "n-triples" (see issue #206)
* Accept-headers are formatted in locale-independent fashion now (see issue #208)
EasyRdf 0.8.0
=============
......
Contributing to EasyRdf
=======================
Contributions to the EasyRdf codebase are welcome using the usual Github pull request workflow.
To run the code style checker:
```
make cs
```
You can run the PHP unit test suite with:
```
make test
make test-lib
```
Unit tests are automatically run after being received by Github:
http://ci.aelius.com/job/easyrdf/
The tests for the examples are run in a sperate test:
The tests for the examples are run separately:
http://ci.aelius.com/job/easyrdf-examples/
Notes
-----
* Please ask on the [mailing list] before starting work on any significant chnages
* Please ask on the [mailing list] before starting work on any significant changes
* Please write tests for any new features or bug fixes. The tests should be checked in the same commit as the code.
[mailing list]:http://groups.google.com/group/easyrdf
This diff is collapsed.
{
"name": "easyrdf/easyrdf",
"description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.",
"version": "0.8.0",
"version": "0.9.0",
"type": "library",
"keywords": ["RDF", "Semantic Web", "Linked Data", "Turtle", "RDFa", "SPARQL"],
"homepage": "http://www.easyrdf.org/",
......@@ -12,6 +12,11 @@
"email": "njh@aelius.com",
"homepage": "http://www.aelius.com/njh/",
"role": "Developer"
},
{
"name": "Alexey Zakhlestin",
"email": "indeyets@gmail.com",
"role": "Developer"
}
],
"support": {
......@@ -20,18 +25,17 @@
"irc": "irc://chat.freenode.net/easyrdf"
},
"require": {
"php": ">=5.2.8"
"php": ">=5.2.8",
"ext-mbstring": "*",
"ext-pcre": "*"
},
"suggest": {
"ml/json-ld": "dev-master"
"ml/json-ld": "~1.0"
},
"require-dev": {
"phpunit/PHPUnit": ">=3.5.15",
"squizlabs/php_codesniffer": ">=1.4.3",
"sami/sami": "dev-master"
},
"replace": {
"njh/easyrdf": "self.version"
"phpunit/PHPUnit": "~3.5",
"squizlabs/php_codesniffer": "~1.4.3",
"sami/sami": "~1.4"
},
"autoload": {
"psr-0": { "EasyRdf_": "lib/" }
......
......@@ -107,7 +107,7 @@ public static function getHttpAcceptHeader($extraTypes = array())
if ($q == 1.0) {
$acceptStr .= $type;
} else {
$acceptStr .= sprintf("%s;q=%1.1f", $type, $q);
$acceptStr .= sprintf("%s;q=%1.1F", $type, $q);
}
}
return $acceptStr;
......@@ -238,7 +238,7 @@ public static function guessFormat($data, $filename = null)
}
// First try and identify by the filename
if ($filename and preg_match("/\.(\w+)$/", $filename, $matches)) {
if ($filename and preg_match('/\.(\w+)$/', $filename, $matches)) {
foreach (self::$formats as $format) {
if (in_array($matches[1], $format->extensions)) {
return $format;
......@@ -248,21 +248,21 @@ public static function guessFormat($data, $filename = null)
// Then try and guess by the first 1024 bytes of content
$short = substr($data, 0, 1024);
if (preg_match("/^\s*\{/", $short)) {
if (preg_match('/^\s*\{/', $short)) {
return self::getFormat('json');
} elseif (preg_match("/<rdf:/i", $short)) {
} elseif (preg_match('/<rdf:/i', $short)) {
return self::getFormat('rdfxml');
} elseif (preg_match("/@prefix\s|@base\s/", $short)) {
return self::getFormat('turtle');
} elseif (preg_match("/^\s*<.+> <.+>/m", $short)) {
return self::getFormat('ntriples');
} elseif (preg_match("|http://www.w3.org/2005/sparql-results|", $short)) {
} elseif (preg_match('|http://www.w3.org/2005/sparql-results|', $short)) {
return self::getFormat('sparql-xml');
} elseif (preg_match("/\WRDFa\W/i", $short)) {
} elseif (preg_match('/\WRDFa\W/i', $short)) {
return self::getFormat('rdfa');
} elseif (preg_match("/<!DOCTYPE html|<html/i", $short)) {
} elseif (preg_match('/<!DOCTYPE html|<html/i', $short)) {
# We don't support any other microformats embedded in HTML
return self::getFormat('rdfa');
} elseif (preg_match('/@prefix\s|@base\s/', $short)) {
return self::getFormat('turtle');
} elseif (preg_match('/^\s*<.+> <.+>/m', $short)) {
return self::getFormat('ntriples');
} else {
return null;
}
......@@ -541,6 +541,16 @@ public function __toString()
array('json')
);
EasyRdf_Format::register(
'jsonld',
'JSON-LD',
'http://www.w3.org/TR/json-ld/',
array(
'application/ld+json' => 1.0
),
array('jsonld')
);
EasyRdf_Format::register(
'ntriples',
'N-Triples',
......@@ -668,6 +678,7 @@ public function __toString()
*/
EasyRdf_Format::registerParser('json', 'EasyRdf_Parser_Json');
EasyRdf_Format::registerParser('jsonld', 'EasyRdf_Parser_JsonLd');
EasyRdf_Format::registerParser('ntriples', 'EasyRdf_Parser_Ntriples');
EasyRdf_Format::registerParser('php', 'EasyRdf_Parser_RdfPhp');
EasyRdf_Format::registerParser('rdfxml', 'EasyRdf_Parser_RdfXml');
......
......@@ -322,8 +322,11 @@ public function load($uri = null, $format = null)
// If we didn't get any location, stop redirecting
break;
} else {
throw new EasyRdf_Exception(
"HTTP request for $requestUrl failed: ".$response->getMessage()
throw new EasyRdf_Http_Exception(
"HTTP request for {$requestUrl} failed: ".$response->getMessage(),
$response->getStatus(),
null,
$response->getBody()
);
}
} while ($redirectCounter < $this->maxRedirects);
......@@ -431,7 +434,7 @@ protected function checkResourceParam(&$resource, $allowNull = false)
}
} elseif ($resource === null) {
throw new InvalidArgumentException(
"\$resource cannot be null"
"\$resource should be either IRI, blank-node identifier or EasyRdf_Resource. got null"
);
}
......@@ -442,7 +445,7 @@ protected function checkResourceParam(&$resource, $allowNull = false)
} elseif (is_string($resource)) {
if ($resource == '') {
throw new InvalidArgumentException(
"\$resource cannot be an empty string"
"\$resource should be either IRI, blank-node identifier or EasyRdf_Resource. got empty string"
);
} elseif (preg_match("|^<(.+)>$|", $resource, $matches)) {
$resource = $matches[1];
......@@ -451,7 +454,7 @@ protected function checkResourceParam(&$resource, $allowNull = false)
}
} else {
throw new InvalidArgumentException(
"\$resource should be a string or an EasyRdf_Resource"
"\$resource should be either IRI, blank-node identifier or EasyRdf_Resource"
);
}
}
......@@ -1395,13 +1398,10 @@ public function dumpResource($resource, $format = 'html')
*/
public function type($resource = null)
{
$this->checkResourceParam($resource, true);
$type = $this->typeAsResource($resource);
if ($resource) {
$type = $this->get($resource, 'rdf:type', 'resource');
if ($type) {
return EasyRdf_Namespace::shorten($type);
}
if ($type) {
return EasyRdf_Namespace::shorten($type);
}
return null;
......@@ -1437,18 +1437,32 @@ public function typeAsResource($resource = null)
*/
public function types($resource = null)
{
$this->checkResourceParam($resource, true);
$resources = $this->typesAsResources($resource);
$types = array();
if ($resource) {
foreach ($this->all($resource, 'rdf:type', 'resource') as $type) {
$types[] = EasyRdf_Namespace::shorten($type);
}
foreach ($resources as $type) {
$types[] = EasyRdf_Namespace::shorten($type);
}
return $types;
}
/**
* Get the resource types of the graph as a EasyRdf_Resource
*
* @return EasyRdf_Resource[]
*/
public function typesAsResources($resource = null)
{
$this->checkResourceParam($resource, true);
if ($resource) {
return $this->all($resource, 'rdf:type', 'resource');
}
return array();
}
/** Check if a resource is of the specified type
*
* @param string $resource The resource to check the type of
......
......@@ -45,6 +45,11 @@
*/
class EasyRdf_GraphStore
{
/**
* Use to reference default graph of triplestore
*/
const DEFAULT_GRAPH = 'urn:easyrdf:default-graph';
/** The address of the GraphStore endpoint */
private $uri = null;
private $parsedUri = null;
......@@ -75,17 +80,34 @@ public function getUri()
* a URI relative to the URI of the graph store.
*
* @param string $uriRef The URI of graph desired
* @return object EasyRdf_Graph The graph requested
* @return EasyRdf_Graph The graph requested
*/
public function get($uriRef)
{
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$graph = new EasyRdf_Graph($graphUri);
if ($uriRef === self::DEFAULT_GRAPH) {
$dataUrl = $this->urlForGraph(self::DEFAULT_GRAPH);
$graph = new EasyRdf_Graph();
} else {
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$graph = new EasyRdf_Graph($graphUri);
}
$graph->load($dataUrl);
return $graph;
}
/**
* Fetch default graph from the graph store
* @return EasyRdf_Graph
*/
public function getDefault()
{
return $this->get(self::DEFAULT_GRAPH);
}
/** Send some graph data to the graph store
*
* This method is used by insert() and replace()
......@@ -95,7 +117,7 @@ public function get($uriRef)
protected function sendGraph($method, $graph, $uriRef, $format)
{
if (is_object($graph) and $graph instanceof EasyRdf_Graph) {
if ($uriRef == null) {
if ($uriRef === null) {
$uriRef = $graph->getUri();
}
$data = $graph->serialise($format);
......@@ -103,11 +125,19 @@ protected function sendGraph($method, $graph, $uriRef, $format)
$data = $graph;
}
if ($uriRef === null) {
throw new InvalidArgumentException('Graph IRI is not specified');
}
$formatObj = EasyRdf_Format::getFormat($format);
$mimeType = $formatObj->getDefaultMimeType();
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
if ($uriRef === self::DEFAULT_GRAPH) {
$dataUrl = $this->urlForGraph(self::DEFAULT_GRAPH);
} else {
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
}
$client = EasyRdf_Http::getDefaultHttpClient();
$client->resetParameters(true);
......@@ -115,12 +145,15 @@ protected function sendGraph($method, $graph, $uriRef, $format)
$client->setMethod($method);
$client->setRawData($data);
$client->setHeaders('Content-Type', $mimeType);
$response = $client->request();
if (!$response->isSuccessful()) {
throw new EasyRdf_Exception(
"HTTP request for $dataUrl failed: ".$response->getMessage()
"HTTP request for {$dataUrl} failed: ".$response->getMessage()
);
}
return $response;
}
......@@ -135,16 +168,34 @@ protected function sendGraph($method, $graph, $uriRef, $format)
* The $format parameter can be given to specify the serialisation
* used to send the graph data to the graph store.
*
* @param object EasyRdfGraph $graph The URI of graph desired
* @param string $uriRef The URI of graph to be replaced
* @param string $format The format of the data to send to the graph store
* @return object EasyRdf_Http_Response The response from the graph store
* @param EasyRdf_Graph|string $graph Data
* @param string $uriRef The URI of graph to be replaced
* @param string $format The format of the data to send to the graph store
* @return EasyRdf_Http_Response The response from the graph store
*/
public function replace($graph, $uriRef = null, $format = 'ntriples')
{
return $this->sendGraph('PUT', $graph, $uriRef, $format);
}
/**
* Replace the contents of default graph in the graph store with new data
*
* The $graph parameter is the EasyRdf_Graph object to be sent to the
* graph store. Alternatively it can be a string, already serialised.
*
* The $format parameter can be given to specify the serialisation
* used to send the graph data to the graph store.
*
* @param EasyRdf_Graph|string $graph Data
* @param string $format The format of the data to send to the graph store
* @return EasyRdf_Http_Response The response from the graph store
*/
public function replaceDefault($graph, $format = 'ntriples')
{
return self::replace($graph, self::DEFAULT_GRAPH, $format);
}
/** Add data to a graph in the graph store
*
* The $graph parameter is the EasyRdf_Graph object to be sent to the
......@@ -156,9 +207,9 @@ public function replace($graph, $uriRef = null, $format = 'ntriples')
* The $format parameter can be given to specify the serialisation
* used to send the graph data to the graph store.
*
* @param object EasyRdfGraph $graph The URI of graph desired
* @param string $uriRef The URI of graph to be added to
* @param string $format The format of the data to send to the graph store
* @param EasyRdf_Graph|string $graph Data
* @param string $uriRef The URI of graph to be added to
* @param string $format The format of the data to send to the graph store
* @return object EasyRdf_Http_Response The response from the graph store
*/
public function insert($graph, $uriRef = null, $format = 'ntriples')
......@@ -166,41 +217,81 @@ public function insert($graph, $uriRef = null, $format = 'ntriples')
return $this->sendGraph('POST', $graph, $uriRef, $format);
}
/** Delete a graph from the graph store
/**
* Add data to default graph of the graph store
*
* The $graph parameter is the EasyRdf_Graph object to be sent to the
* graph store. Alternatively it can be a string, already serialised.
*
* The $format parameter can be given to specify the serialisation
* used to send the graph data to the graph store.
*
* @param EasyRdf_Graph|string $graph Data
* @param string $format The format of the data to send to the graph store
* @return object EasyRdf_Http_Response The response from the graph store
*/
public function insertIntoDefault($graph, $format = 'ntriples')
{
return $this->insert($graph, self::DEFAULT_GRAPH, $format);