예제 #1
0
 /**
  * Requires the following three parameters.
  * @param string $endpoint SPARQL endpoint address.
  * @param object $graph an EasyRDF SPARQL graph instance.
  * @param object $model a Model instance.
  */
 public function __construct($endpoint, $graph, $model)
 {
     // if special cache control (typically no-cache) was requested by the
     // client, set the same type of cache control headers also in subsequent
     // in the SPARQL requests (this is useful for performance testing)
     $cache_control = filter_input(INPUT_SERVER, 'HTTP_CACHE_CONTROL', FILTER_SANITIZE_STRING);
     $pragma = filter_input(INPUT_SERVER, 'HTTP_PRAGMA', FILTER_SANITIZE_STRING);
     if ($cache_control !== null || $pragma !== null) {
         $val = $pragma !== null ? $pragma : $cache_control;
         // configure the HTTP client used by EasyRdf_Sparql_Client
         $httpclient = EasyRdf_Http::getDefaultHttpClient();
         $httpclient->setHeaders('Cache-Control', $val);
         EasyRdf_Http::setDefaultHttpClient($httpclient);
         // actually redundant..
     }
     // create the EasyRDF SPARQL client instance to use
     $this->client = new EasyRdf_Sparql_Client($endpoint);
     $this->graph = $graph;
     $this->model = $model;
     // set graphClause so that it can be used by all queries
     if ($this->isDefaultEndpoint()) {
         $this->graphClause = "GRAPH {$graph}";
     } elseif ($graph) {
         $this->graphClause = "GRAPH <{$graph}>";
     } else {
         $this->graphClause = "";
     }
 }
 public function setUp()
 {
     EasyRdf_Http::setDefaultHttpClient($this->_client = new EasyRdf_Http_MockClient());
     $this->_graphStore = new EasyRdf_GraphStore('http://localhost:8080/data/');
     // Ensure that the built-in n-triples parser is used
     EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Ntriples');
 }
 /**
  * Set up the test suite before each test
  */
 public function setUp()
 {
     EasyRdf_Http::setDefaultHttpClient($this->_client = new EasyRdf_Http_MockClient());
     $this->_graph = new EasyRdf_Graph('http://example.com/graph');
     $this->_uri = 'http://example.com/#me';
     $this->_graph->setType($this->_uri, 'foaf:Person');
     $this->_graph->add($this->_uri, 'rdf:test', 'Test A');
     $this->_graph->add($this->_uri, 'rdf:test', new EasyRdf_Literal('Test B', 'en'));
 }
예제 #4
0
 /**
  * Just an helper to use HttPClient as default EastRdf_default_client)
  */
 public static function useIdentity($username = null, $password = null, $timeout = null)
 {
     $httpClient = \EasyRdf_Http::getDefaultHttpClient();
     // if current default http client does not provide setAuth use a new instance of HttpClient
     if (!($httpClient instanceof \Zend_Http_Client or $httpClient instanceof HttpClient)) {
         $httpClient = new HttpClient(null, array('maxredirects' => 5, 'useragent' => 'BOTK HttpClient', 'timeout' => ini_get('max_execution_time') || 30));
     }
     $httpClient->setAuth($username, $password);
     return \EasyRdf_Http::setDefaultHttpClient($httpClient);
 }
 /**
  * Set up the test suite before each test
  */
 public function setUp()
 {
     // Reset to built-in parsers
     EasyRdf_Format::registerParser('ntriples', 'EasyRdf_Parser_Ntriples');
     EasyRdf_Format::registerParser('rdfxml', 'EasyRdf_Parser_RdfXml');
     EasyRdf_Format::registerParser('turtle', 'EasyRdf_Parser_Turtle');
     EasyRdf_Http::setDefaultHttpClient($this->_client = new EasyRdf_Http_MockClient());
     $this->_graph = new EasyRdf_Graph('http://example.com/graph');
     $this->_uri = 'http://example.com/#me';
     $this->_graph->setType($this->_uri, 'foaf:Person');
     $this->_graph->add($this->_uri, 'rdf:test', 'Test A');
     $this->_graph->add($this->_uri, 'rdf:test', new EasyRdf_Literal('Test B', 'en'));
 }
예제 #6
0
 public function testSetDefaultHttpClientString()
 {
     $this->setExpectedException('InvalidArgumentException', '$httpClient should be an object of class Zend_Http_Client or EasyRdf_Http_Client');
     EasyRdf_Http::setDefaultHttpClient('foobar');
 }
예제 #7
0
 public function testLoad()
 {
     EasyRdf_Http::setDefaultHttpClient($client = new EasyRdf_Http_MockClient());
     $client->addMock('GET', 'http://example.com/foaf.json', readFixture('foaf.json'));
     $graph = new EasyRdf_Graph('http://example.com/');
     $resource = $graph->resource('http://example.com/foaf.json');
     $resource->load();
     $this->assertStringEquals('Joe Bloggs', $graph->get('http://www.example.com/joe#me', 'foaf:name'));
 }
예제 #8
0
파일: Model.php 프로젝트: jneubert/Skosmos
 private function fetchResourceFromUri($uri)
 {
     try {
         // change the timeout setting for external requests
         $httpclient = EasyRdf_Http::getDefaultHttpClient();
         $httpclient->setConfig(array('timeout' => $this->getConfig()->getHttpTimeout()));
         EasyRdf_Http::setDefaultHttpClient($httpclient);
         $client = EasyRdf_Graph::newAndLoad(EasyRdf_Utils::removeFragmentFromUri($uri));
         return $client->resource($uri);
     } catch (Exception $e) {
         return null;
     }
 }
 public function setUp()
 {
     EasyRdf_Http::setDefaultHttpClient($this->_client = new EasyRdf_Http_MockClient());
     $this->_sparql = new EasyRdf_Sparql_Client('http://localhost:8080/sparql');
 }
 * This example creates a simple graph in memory, saves it to a local
 * graphstore and then fetches the data back using a SPARQL SELECT query.
 * Zend's curl HTTP client adaptor is used to perform the HTTP requests.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2011 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
// require the Zend Autoloader
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
// use the CURL based HTTP client adaptor
$client = new Zend_Http_Client(null, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'keepalive' => true, 'useragent' => "EasyRdf/zendtest"));
EasyRdf_Http::setDefaultHttpClient($client);
// Load the parsers and serialisers that we are going to use
# FIXME: better way to do this?
$autoloader->autoload('EasyRdf_Serialiser_Ntriples');
$autoloader->autoload('EasyRdf_Parser_Ntriples');
?>

<html>
<head>
  <title>Zend Framework Example</title>
</head>
<body>
<h1>Zend Framework Example</h1>

<?php 
# Load some sample data into a graph
예제 #11
0
 /** A basic HTML response check using curl to check identifier exists
  * @access public
  * @return array
  */
 public function checkType($identifier)
 {
     $key = md5($identifier . 'CheckRrcTypes');
     if (!$this->getCache()->test($key)) {
         $client = new Zend_Http_Client(null, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'keepalive' => true, 'useragent' => "finds.org.uk/easyrdf"));
         $client->setHeaders(array('accept' => 'application/sparql-results+xml'));
         EasyRdf_Http::setDefaultHttpClient($client);
         EasyRdf_Namespace::set('nm', 'http://nomisma.org/id/');
         EasyRdf_Namespace::set('nmo', 'http://nomisma.org/ontology#');
         EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
         EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
         $sparql = new EasyRdf_Sparql_Client('http://nomisma.org/query');
         $data = $sparql->query('SELECT * WHERE {' . '  ?type ?role nm:' . $identifier . ' ;' . '   a nmo:TypeSeriesItem ;' . '  skos:prefLabel ?label' . '  OPTIONAL {?type nmo:hasStartDate ?startDate}' . '  OPTIONAL {?type nmo:hasEndDate ?endDate}' . '  FILTER(langMatches(lang(?label), "en"))' . ' } ORDER BY ?label');
         $this->getCache()->save($data);
     } else {
         $data = $this->getCache()->load($key);
     }
     return $data;
 }
예제 #12
0
 /** Construct the function
  * @access public
  */
 public function __construct()
 {
     $client = new Zend_Http_Client(null, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'keepalive' => true, 'useragent' => "findsorguk", 'timeout' => 30));
     EasyRdf_Http::setDefaultHttpClient($client);
 }