public static function EasyRdf_Utils::dumpLiteralValue

Return pretty-print view of a literal

This method is mainly intended for internal use and is used by EasyRdf_Graph and EasyRdf_Sparql_Result to format a literal for display.

Parameters

mixed $literal An EasyRdf_Literal object or an associative array:

bool $html Set to true to format the dump using HTML:

string $color The colour of the text:

Return value

string

2 calls to EasyRdf_Utils::dumpLiteralValue()
EasyRdf_Graph::dumpResource in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Return a human readable view of a resource and its properties
EasyRdf_Literal::dumpValue in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php
Return pretty-print view of the literal

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php, line 161

Class

EasyRdf_Utils
Class containing static utility functions

Code

public static function dumpLiteralValue($literal, $html = true, $color = 'black') {
  if (is_object($literal)) {
    $literal = $literal
      ->toArray();
  }
  elseif (!is_array($literal)) {
    $literal = array(
      'value' => $literal,
    );
  }
  $text = '"' . $literal['value'] . '"';
  if (isset($literal['lang'])) {
    $text .= '@' . $literal['lang'];
  }
  if (isset($literal['datatype'])) {
    $datatype = EasyRdf_Namespace::shorten($literal['datatype']);
    $text .= "^^{$datatype}";
  }
  if ($html) {
    return "<span style='color:{$color}'>" . htmlentities($text, ENT_COMPAT, "UTF-8") . "</span>";
  }
  else {
    return $text;
  }
}