Skip to content
This repository
branch: master
Nicholas Humfrey
file 62 lines (53 sloc) 1.888 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<?php
    /**
* Using EasyRdf with the Zend Framework
*
* This example demonstrates using Zend_Http_Client and
* Zend_Loader_Autoloader with EasyRdf.
*
* It 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-2013 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);
?>

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

<?php
    # Load some sample data into a graph
    $graph = new EasyRdf_Graph('http://example.com/joe');
    $joe = $graph->resource('http://example.com/joe#me', 'foaf:Person');
    $joe->add('foaf:name', 'Joe Bloggs');
    $joe->addResource('foaf:homepage', 'http://example.com/joe/');

    # Store it in a local graphstore
    $store = new EasyRdf_GraphStore('http://localhost:8080/data/');
    $store->replace($graph);

    # Now make a query to the graphstore
    $sparql = new EasyRdf_Sparql_Client('http://localhost:8080/sparql/');
    $result = $sparql->query('SELECT * WHERE {<http://example.com/joe#me> ?p ?o}');
    echo $result->dump();
?>

</body>
</html>
Something went wrong with that request. Please try again.