You are here

public function EasyRdf_Serialiser_Ntriples::serialiseValue in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php \EasyRdf_Serialiser_Ntriples::serialiseValue()

Serialise an RDF value into N-Triples

The value can either be an array in RDF/PHP form, or an EasyRdf_Literal or EasyRdf_Resource object.

Parameters

array|object $value An associative array or an object:

Return value

string The RDF value serialised to N-Triples

Throws

EasyRdf_Exception

1 call to EasyRdf_Serialiser_Ntriples::serialiseValue()
EasyRdf_Serialiser_Ntriples::serialise in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php
Serialise an EasyRdf_Graph into N-Triples

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php, line 164

Class

EasyRdf_Serialiser_Ntriples
Class to serialise an EasyRdf_Graph to N-Triples with no external dependancies.

Code

public function serialiseValue($value) {
  if (is_object($value)) {
    $value = $value
      ->toRdfPhp();
  }
  if ($value['type'] == 'uri' or $value['type'] == 'bnode') {
    return $this
      ->serialiseResource($value['value']);
  }
  elseif ($value['type'] == 'literal') {
    $escaped = $this
      ->escapeString($value['value']);
    if (isset($value['lang'])) {
      $lang = $this
        ->escapeString($value['lang']);
      return '"' . $escaped . '"' . '@' . $lang;
    }
    elseif (isset($value['datatype'])) {
      $datatype = $this
        ->escapeString($value['datatype']);
      return '"' . $escaped . '"' . "^^<{$datatype}>";
    }
    else {
      return '"' . $escaped . '"';
    }
  }
  else {
    throw new EasyRdf_Exception("Unable to serialise object of type '" . $value['type'] . "' to ntriples: ");
  }
}