public function EasyRdf_Serialiser_Turtle::serialiseLiteral in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Turtle.php \EasyRdf_Serialiser_Turtle::serialiseLiteral()
Given an EasyRdf_Literal object, convert it into a string, suitable to be written to a Turtle document. Supports multiline literals and literals with datatypes or languages.
Parameters
EasyRdf_Literal $literal:
Return value
string
1 call to EasyRdf_Serialiser_Turtle::serialiseLiteral()
- EasyRdf_Serialiser_Turtle::serialiseObject in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Serialiser/ Turtle.php - Convert an EasyRdf object into a string suitable to be written to a Turtle document.
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Serialiser/ Turtle.php, line 120
Class
- EasyRdf_Serialiser_Turtle
- Class to serialise an EasyRdf_Graph to Turtle with no external dependancies.
Code
public function serialiseLiteral($literal) {
$value = strval($literal);
$quoted = self::quotedString($value);
if ($datatype = $literal
->getDatatypeUri()) {
if ($datatype == 'http://www.w3.org/2001/XMLSchema#integer') {
return sprintf('%d', $value);
}
elseif ($datatype == 'http://www.w3.org/2001/XMLSchema#decimal') {
return sprintf('%s', $value);
}
elseif ($datatype == 'http://www.w3.org/2001/XMLSchema#double') {
return sprintf('%e', $value);
}
elseif ($datatype == 'http://www.w3.org/2001/XMLSchema#boolean') {
return sprintf('%s', $value);
}
else {
$escaped = $this
->serialiseResource($datatype, true);
return sprintf('%s^^%s', $quoted, $escaped);
}
}
elseif ($lang = $literal
->getLang()) {
return $quoted . '@' . $lang;
}
else {
return $quoted;
}
}