Commit 9ad50642 authored by webchick's avatar webchick

Issue #1866858 by linclark, scor: Test RDFa by parsing RDFa (add the easyrdf library).

parent 626a067d
......@@ -15,7 +15,8 @@
"doctrine/common": "2.3.*@stable",
"guzzle/http": "*",
"kriswallsmith/assetic": "1.1.*@alpha",
"symfony-cmf/routing": "1.0.*@dev"
"symfony-cmf/routing": "1.0.*@dev",
"njh/easyrdf": "0.8.*"
},
"minimum-stability": "dev"
}
......@@ -359,6 +359,39 @@
"routing"
]
},
{
"name": "njh/easyrdf",
"description": "EasyRdf is a PHP library designed to make it easy to consume and produce RDF.",
"version": "0.8.0",
"type": "library",
"keywords": ["RDF", "Semantic Web", "Turtle", "RDFa"],
"homepage": "http://www.aelius.com/njh/easyrdf/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Nicholas Humfrey",
"email": "njh@aelius.com",
"homepage": "http://www.aelius.com/njh/",
"role": "Developer"
}
],
"support": {
"forum": "http://groups.google.com/group/easyrdf/",
"issues": "http://github.com/njh/easyrdf/issues"
},
"require": {
"php": ">=5.2.8"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/njh/easyrdf"
}
],
"autoload": {
"psr-0": { "EasyRdf": "lib/" }
}
},
{
"name": "symfony/class-loader",
"version": "dev-master",
......
......@@ -23,4 +23,5 @@
'Guzzle\\Common' => $vendorDir . '/guzzle/common/',
'Doctrine\\Common' => $vendorDir . '/doctrine/common/lib/',
'Assetic' => $vendorDir . '/kriswallsmith/assetic/src/',
'EasyRdf_' => $vendorDir . '/njh/easyrdf/lib/',
);
<?php
/**
* EasyRdf
*
* Use this file to load the core of EasyRdf, if you don't have an autoloader.
*
*
* LICENSE
*
* Copyright (c) 2009-2011 Nicholas J Humfrey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package EasyRdf
* @copyright Copyright (c) 2011 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id$
*/
/**
* @see EasyRdf_Exception
*/
require_once "EasyRdf/Exception.php";
/**
* @see EasyRdf_Format
*/
require_once "EasyRdf/Format.php";
/**
* @see EasyRdf_Graph
*/
require_once "EasyRdf/Graph.php";
/**
* @see EasyRdf_GraphStore
*/
require_once "EasyRdf/GraphStore.php";
/**
* @see EasyRdf_Http
*/
require_once "EasyRdf/Http.php";
/**
* @see EasyRdf_Http_Client
*/
require_once "EasyRdf/Http/Client.php";
/**
* @see EasyRdf_Http_Response
*/
require_once "EasyRdf/Http/Response.php";
/**
* @see EasyRdf_Namespace
*/
require_once "EasyRdf/Namespace.php";
/**
* @see EasyRdf_Literal
*/
require_once "EasyRdf/Literal.php";
/**
* @see EasyRdf_Literal_Boolean
*/
require_once "EasyRdf/Literal/Boolean.php";
/**
* @see EasyRdf_Literal_Date
*/
require_once "EasyRdf/Literal/Date.php";
/**
* @see EasyRdf_Literal_DateTime
*/
require_once "EasyRdf/Literal/DateTime.php";
/**
* @see EasyRdf_Literal_Decimal
*/
require_once "EasyRdf/Literal/Decimal.php";
/**
* @see EasyRdf_Literal_HexBinary
*/
require_once "EasyRdf/Literal/HexBinary.php";
/**
* @see EasyRdf_Literal_HTML
*/
require_once "EasyRdf/Literal/HTML.php";
/**
* @see EasyRdf_Literal_Integer
*/
require_once "EasyRdf/Literal/Integer.php";
/**
* @see EasyRdf_Literal_XML
*/
require_once "EasyRdf/Literal/XML.php";
/**
* @see EasyRdf_ParsedUri
*/
require_once "EasyRdf/ParsedUri.php";
/**
* @see EasyRdf_Parser
*/
require_once "EasyRdf/Parser.php";
/**
* @see EasyRdf_Parser_RdfPhp
*/
require_once "EasyRdf/Parser/RdfPhp.php";
/**
* @see EasyRdf_Parser_Ntriples
*/
require_once "EasyRdf/Parser/Ntriples.php";
/**
* @see EasyRdf_Parser_Json
*/
require_once "EasyRdf/Parser/Json.php";
/**
* @see EasyRdf_Parser_Rdfa
*/
require_once "EasyRdf/Parser/Rdfa.php";
/**
* @see EasyRdf_Parser_RdfXml
*/
require_once "EasyRdf/Parser/RdfXml.php";
/**
* @see EasyRdf_Parser_Turtle
*/
require_once "EasyRdf/Parser/Turtle.php";
/**
* @see EasyRdf_Resource
*/
require_once "EasyRdf/Resource.php";
/**
* @see EasyRdf_Serialiser
*/
require_once "EasyRdf/Serialiser.php";
/**
* @see EasyRdf_Serialiser_GraphViz
*/
require_once "EasyRdf/Serialiser/GraphViz.php";
/**
* @see EasyRdf_Serialiser_RdfPhp
*/
require_once "EasyRdf/Serialiser/RdfPhp.php";
/**
* @see EasyRdf_Serialiser_Ntriples
*/
require_once "EasyRdf/Serialiser/Ntriples.php";
/**
* @see EasyRdf_Serialiser_Json
*/
require_once "EasyRdf/Serialiser/Json.php";
/**
* @see EasyRdf_Serialiser_RdfXml
*/
require_once "EasyRdf/Serialiser/RdfXml.php";
/**
* @see EasyRdf_Serialiser_Turtle
*/
require_once "EasyRdf/Serialiser/Turtle.php";
/**
* @see EasyRdf_Sparql_Client
*/
require_once "EasyRdf/Sparql/Client.php";
/**
* @see EasyRdf_Sparql_Result
*/
require_once "EasyRdf/Sparql/Result.php";
/**
* @see EasyRdf_TypeMapper
*/
require_once "EasyRdf/TypeMapper.php";
/**
* @see EasyRdf_Utils
*/
require_once "EasyRdf/Utils.php";
<?php
/**
* EasyRdf
*
* LICENSE
*
* Copyright (c) 2009-2010 Nicholas J Humfrey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2010 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id$
*/
/**
* EasyRdf Exception class
*
* All exceptions thrown by EasyRdf are an instance of this class.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2010 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class EasyRdf_Exception extends Exception
{
// Comment to make PHP CodeSniffer happy
}
This diff is collapsed.
This diff is collapsed.
<?php
/**
* EasyRdf
*
* LICENSE
*
* Copyright (c) 2009-2011 Nicholas J Humfrey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2011 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id$
*/
/**
* A class for fetching, saving and deleting graphs to a Graph Store.
* Implementation of the SPARQL 1.1 Graph Store HTTP Protocol.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2011 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class EasyRdf_GraphStore
{
/** The address of the GraphStore endpoint */
private $uri = null;
private $parsedUri = null;
/** Create a new SPARQL Graph Store client
*
* @param string $uri The address of the graph store endpoint
*/
public function __construct($uri)
{
$this->uri = $uri;
$this->parsedUri = new EasyRdf_ParsedUri($uri);
}
/** Get the URI of the graph store
*
* @return string The URI of the graph store
*/
public function getUri()
{
return $this->uri;
}
/** Fetch a named graph from the graph store
*
* The URI can either be a full absolute URI or
* 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
*/
public function get($uriRef)
{
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$graph = new EasyRdf_Graph($graphUri);
$graph->load($dataUrl);
return $graph;
}
/** Send some graph data to the graph store
*
* This method is used by insert() and replace()
*
* @ignore
*/
protected function sendGraph($method, $graph, $uriRef, $format)
{
if (is_object($graph) and $graph instanceof EasyRdf_Graph) {
if ($uriRef == null) {
$uriRef = $graph->getUri();
}
$data = $graph->serialise($format);
} else {
$data = $graph;
}
$formatObj = EasyRdf_Format::getFormat($format);
$mimeType = $formatObj->getDefaultMimeType();
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$client = EasyRdf_Http::getDefaultHttpClient();
$client->resetParameters(true);
$client->setUri($dataUrl);
$client->setMethod($method);
$client->setRawData($data);
$client->setHeaders('Content-Type', $mimeType);
$client->setHeaders('Content-Length', strlen($data));
$response = $client->request();
if (!$response->isSuccessful()) {
throw new EasyRdf_Exception(
"HTTP request for $dataUrl failed: ".$response->getMessage()
);
}
return $response;
}
/** Replace the contents of a 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 URI can either be a full absolute URI or
* a URI relative to the URI of the graph store.
*
* 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
*/
public function replace($graph, $uriRef = null, $format = 'ntriples')
{
return $this->sendGraph('PUT', $graph, $uriRef, $format);
}
/** Add data to a graph in 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 URI can either be a full absolute URI or
* a URI relative to the URI of the graph store.
*
* 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
* @return object EasyRdf_Http_Response The response from the graph store
*/
public function insert($graph, $uriRef = null, $format = 'ntriples')
{
return $this->sendGraph('POST', $graph, $uriRef, $format);
}
/** Delete a graph from the graph store
*
* The URI can either be a full absolute URI or
* a URI relative to the URI of the graph store.
*
* @param string $uriRef The URI of graph to be added to
* @return object EasyRdf_Http_Response The response from the graph store
*/
public function delete($uriRef)
{
$graphUri = $this->parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$client = EasyRdf_Http::getDefaultHttpClient();
$client->resetParameters(true);
$client->setUri($dataUrl);
$client->setMethod('DELETE');
$response = $client->request();
if (!$response->isSuccessful()) {
throw new EasyRdf_Exception(
"HTTP request to delete $dataUrl failed: ".$response->getMessage()
);
}
return $response;
}
/** Work out the full URL for a graph store request.
* by checking if if it is a direct or indirect request.
* @ignore
*/
protected function urlForGraph($url)
{
if (strpos($url, $this->uri) === false) {
$url = $this->uri."?graph=".urlencode($url);
}
return $url;
}
/** Magic method to return URI of the graph store when casted to string
*
* @return string The URI of the graph store
*/
public function __toString()
{
return empty($this->uri) ? '' : $this->uri;
}
}
<?php
/**
* EasyRdf
*
* LICENSE
*
* Copyright (c) 2009-2011 Nicholas J Humfrey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2011 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id$
*/
/**
* Static class to set the HTTP client used by EasyRdf
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2011 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class EasyRdf_Http
{
/** The default HTTP Client object */
private static $defaultHttpClient = null;
/** Set the HTTP Client object used to fetch RDF data
*
* @param object mixed $httpClient The new HTTP client object
* @return object mixed The new HTTP client object
*/
public static function setDefaultHttpClient($httpClient)
{
if (!is_object($httpClient) or
!($httpClient instanceof Zend_Http_Client or
$httpClient instanceof EasyRdf_Http_Client)) {
throw new InvalidArgumentException(
"\$httpClient should be an object of class Zend_Http_Client or EasyRdf_Http_Client"
);
}
return self::$defaultHttpClient = $httpClient;
}
/** Get the HTTP Client object used to fetch RDF data
*
* If no HTTP Client has previously been set, then a new
* default (EasyRdf_Http_Client) client will be created.
*
* @return object mixed The HTTP client object
*/
public static function getDefaultHttpClient()
{
if (!isset(self::$defaultHttpClient)) {
self::$defaultHttpClient = new EasyRdf_Http_Client();
}
return self::$defaultHttpClient;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* EasyRdf
*
* LICENSE
*
* Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author 'Nicholas J Humfrey" may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2012 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id$
*/
/**
* Class that represents an RDF Literal of datatype xsd:boolean
*
* @package EasyRdf
* @link http://www.w3.org/TR/xmlschema-2/#boolean
* @copyright Copyright (c) 2009-2012 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class EasyRdf_Literal_Boolean extends EasyRdf_Literal
{
/** Constructor for creating a new boolean literal
*
* If the value is not a string, then it will be converted to 'true' or 'false'.
*
* @param mixed $value The value of the literal
* @param string $lang Should be null (literals with a datatype can't have a language)
* @param string $datatype Optional datatype (default 'xsd:boolean')
* @return object EasyRdf_Literal_Boolean
*/
public function __construct($value, $lang = null, $datatype = null)
{
if (!is_string($value)) {
$value = $value ? 'true' : 'false';
}
parent::__construct($value, null, $datatype);
}
/** Return the value of the literal cast to a PHP bool
*
* If the value is 'true' or '1' return true, otherwise returns false.
*
* @return bool
*/
public function getValue()
{
return strtolower($this->value) === 'true' or $this->value === '1';
}
/** Return true if the value of the literal is 'true' or '1'
*