protected function EasyRdf_Serialiser_Turtle::serialiseObject

@ignore

1 call to EasyRdf_Serialiser_Turtle::serialiseObject()
EasyRdf_Serialiser_Turtle::serialiseProperties in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php
Protected method to serialise the properties of a resource @ignore

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php, line 89

Class

EasyRdf_Serialiser_Turtle
Class to serialise an EasyRdf_Graph to Turtle with no external dependancies.

Code

protected function serialiseObject($object) {
  if ($object instanceof EasyRdf_Resource) {
    return $this
      ->serialiseResource($object);
  }
  else {
    $value = strval($object);
    $quoted = $this
      ->quotedString($value);
    if ($datatype = $object
      ->getDatatypeUri()) {
      $short = EasyRdf_Namespace::shorten($datatype, true);
      if ($short) {
        $this
          ->addPrefix($short);
        if ($short == 'xsd:integer') {
          return sprintf('%d', $value);
        }
        elseif ($short == 'xsd:decimal') {
          return sprintf('%g', $value);
        }
        elseif ($short == 'xsd:double') {
          return sprintf('%e', $value);
        }
        elseif ($short == 'xsd:boolean') {
          return sprintf('%s', $value ? 'true' : 'false');
        }
        else {
          return sprintf('%s^^%s', $quoted, $short);
        }
      }
      else {
        $datatypeUri = str_replace('>', '\\>', $datatype);
        return sprintf('%s^^<%s>', $quoted, $datatypeUri);
      }
    }
    elseif ($lang = $object
      ->getLang()) {
      return $quoted . '@' . $lang;
    }
    else {
      return $quoted;
    }
  }
}