You are here

public static function EasyRdf_Utils::dumpLiteralValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php \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:

string $format Either 'html' or 'text':

string $color The colour of the text:

Return value

string

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

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php, line 166

Class

EasyRdf_Utils
Class containing static utility functions

Code

public static function dumpLiteralValue($literal, $format = 'html', $color = 'black') {
  if (!preg_match('/^#?[-\\w]+$/', $color)) {
    throw new InvalidArgumentException("\$color must be a legal color code or name");
  }
  if (is_object($literal)) {
    $literal = $literal
      ->toRdfPhp();
  }
  elseif (!is_array($literal)) {
    $literal = array(
      'value' => $literal,
    );
  }
  $text = '"' . $literal['value'] . '"';
  if (isset($literal['lang'])) {
    $text .= '@' . $literal['lang'];
  }
  if (isset($literal['datatype'])) {
    $short = EasyRdf_Namespace::shorten($literal['datatype']);
    if ($short) {
      $text .= "^^{$short}";
    }
    else {
      $text .= "^^<" . $literal['datatype'] . ">";
    }
  }
  if ($format == 'html') {
    return "<span style='color:{$color}'>" . htmlentities($text, ENT_COMPAT, "UTF-8") . "</span>";
  }
  else {
    return $text;
  }
}