public static function EasyRdf_Literal::create

Create a new literal object

PHP values of type bool, int or float, will automatically be converted to the corresponding datatype and PHP sub-class.

If a registered datatype is given, then the registered subclass of EasyRdf_Literal will instantiated.

Note that literals are not required to have a language or datatype. Literals cannot have both a language and a datatype.

Parameters

mixed $value The value of the literal or an associative array:

string $lang The natural language of the literal or null (e.g. 'en'):

string $datatype The datatype of the literal or null (e.g. 'xsd:integer'):

Return value

object EasyRdf_Literal (or subclass of EasyRdf_Literal)

2 calls to EasyRdf_Literal::create()
EasyRdf_Graph::arrayToObject in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Get an EasyRdf_Resource or EasyRdf_Literal object from an associative array. @ignore
EasyRdf_Sparql_Result::newTerm in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Result.php
Create a new EasyRdf_Resource or EasyRdf_Literal depending on the type of data passed in.

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php, line 80

Class

EasyRdf_Literal
Class that represents an RDF Literal

Code

public static function create($value, $lang = null, $datatype = null) {
  if (EasyRdf_Utils::isAssociativeArray($value)) {
    if (isset($value['xml:lang'])) {
      $lang = $value['xml:lang'];
    }
    elseif (isset($value['lang'])) {
      $lang = $value['lang'];
    }
    if (isset($value['datatype'])) {
      $datatype = $value['datatype'];
    }
    $value = isset($value['value']) ? $value['value'] : null;
  }
  if (empty($datatype)) {
    if (empty($lang)) {

      // Automatic datatype selection
      $datatype = self::getDatatypeForValue($value);
    }
  }
  elseif (is_object($datatype)) {
    $datatype = strval($datatype);
  }
  else {

    // Expand shortened URIs (qnames)
    $datatype = EasyRdf_Namespace::expand($datatype);
  }

  // Work out what class to use for this datatype
  if (isset(self::$datatypeMap[$datatype])) {
    $class = self::$datatypeMap[$datatype];
  }
  else {
    $class = 'EasyRdf_Literal';
  }
  return new $class($value, $lang, $datatype);
}