LiteralInterface
extends
TermInterface, TermCompareInterface
in
Description of RdfTerm
Tags
Table of Contents
Constants
- CAST_DATATYPE = 2
- CAST_LEXICAL_FORM = 1
Methods
- __toString() : string
- Should return:
- equals() : bool
- getDatatype() : string
- Returns literal's datatype.
- getLang() : string|null
- Returns literal's language tag.
- getValue() : mixed
- withDatatype() : LiteralInterface
- Returns a new literal being a copy with this one with datatype set to a given value.
- withLang() : LiteralInterface
- Returns a new literal being a copy of this one with a lang tag set to a given value.
- withValue() : LiteralInterface
- Returns a new literal being a copy of this one with a given value.
Constants
CAST_DATATYPE
public
mixed
CAST_DATATYPE
= 2
CAST_LEXICAL_FORM
public
mixed
CAST_LEXICAL_FORM
= 1
Methods
__toString()
Should return:
public
__toString() : string
- an URI for named nodes and blank nodes
- a value in lexical form for literals
For all other kind of terms the return value depends on the implementation
Return values
stringequals()
public
equals(TermInterface $term) : bool
Parameters
- $term : TermInterface
Return values
boolgetDatatype()
Returns literal's datatype.
public
getDatatype() : string
The method must return the actual datatype even if it's implicit. It
means http://www.w3.org/1999/02/22-rdf-syntax-ns#langString
must be
returned for literals with a lang tag and
http://www.w3.org/2001/XMLSchema#string
must be returned for literals
without lang tag and without datatype specified explicitely.
Return values
stringgetLang()
Returns literal's language tag.
public
getLang() : string|null
If a literal lacks a language tag, null should be returned. It means this method can't return an empty string.
Return values
string|nullgetValue()
public
getValue() : mixed
withDatatype()
Returns a new literal being a copy with this one with datatype set to a given value.
public
withDatatype(string $datatype) : LiteralInterface
Be aware it's impossibe to set the datatype to rdf::langString that way as it would require setting a non-empty lang tag. The withLang() method should be used in such a case as it changes the datatype implicitly.
As this method by definition doesn't allow to set a datatype allowing a literal to have a lang tag, it must set returned literal's lang tag to null.
This method must throw a \BadMethodCallException when called with a wrong
datatype (http://www.w3.org/1999/02/22-rdf-syntax-ns#langString
or an
empty one).
Parameters
- $datatype : string
Tags
Return values
LiteralInterfacewithLang()
Returns a new literal being a copy of this one with a lang tag set to a given value.
public
withLang(string|null $lang) : LiteralInterface
Be aware setting a lang tag on a literal without one as well as dropping a lang tag from a literal having it implicitly changes literal's datatype. Setting a lang on a literal without one enforces setting its datatype to rdf:langString while dropping a lang from a literal having it changes literal's datatype to xsd:string (see https://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal for details).
Parameters
- $lang : string|null
Return values
LiteralInterfacewithValue()
Returns a new literal being a copy of this one with a given value.
public
withValue(int|float|string|bool|Stringable $value) : LiteralInterface
If the $value type is int/float/bool, the lang tag of the returned literal is set to null and the datatype is set to a corresponding XSD type (see the constructor documentation). If the $value is string/Stringable, the lang tag and datatype are preserved.
Parameters
- $value : int|float|string|bool|Stringable