Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
67 lines (59 sloc) 1.9 KB
* Basic serialisation example
* This example create a simple FOAF graph in memory and then
* serialises it to the page in the format of choice.
* @package EasyRdf
* @copyright Copyright (c) 2009-2014 Nicholas J Humfrey
* @license
require_once realpath(__DIR__.'/..')."/vendor/autoload.php";
$graph = new \EasyRdf\Graph();
$me = $graph->resource('', 'foaf:Person');
$me->set('foaf:name', 'Joseph Bloggs');
$me->set('foaf:title', 'Mr');
$me->set('foaf:nick', 'Joe');
$me->add('foaf:homepage', $graph->resource(''));
// I made these up; they are not officially part of FOAF
$me->set('foaf:dateOfBirth', new \EasyRdf\Literal\Date('1980-09-08'));
$me->set('foaf:height', 1.82);
$project = $graph->newBnode('foaf:Project');
$project->set('foaf:name', "Joe's current project");
$me->set('foaf:currentProject', $project);
if (isset($_REQUEST['format'])) {
$format = preg_replace('/[^\w\-]+/', '', strtolower($_REQUEST['format']));
} else {
$format = 'ntriples';
<head><title>EasyRdf Serialiser Example</title></head>
<h1>EasyRdf Serialiser Example</h1>
foreach (\EasyRdf\Format::getFormats() as $f) {
if ($f->getSerialiserClass()) {
if ($f->getName() == $format) {
print "<li><b>".$f->getLabel()."</b></li>\n";
} else {
print "<li><a href='?format=$f'>";
print $f->getLabel()."</a></li>\n";
<pre style="margin: 0.5em; padding:0.5em; background-color:#eee; border:dashed 1px grey;">
$data = $graph->serialise($format);
if (!is_scalar($data)) {
$data = var_export($data, true);
print htmlspecialchars($data);