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.
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'):
object EasyRdf_Literal (or subclass of EasyRdf_Literal)
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);
}