Add a literal value as a property of a resource
The resource can either be a resource or the URI of a resource. The value can either be a single value or an array of values.
Example: $graph->add("http://www.example.com", 'dc:title', 'Title of Page');
mixed $resource The resource to add data to:
mixed $property The property name:
mixed $value The value or values for the property:
string $lang The language of the literal:
integer The number of values added
public function addLiteral($resource, $property, $value, $lang = null) {
$this
->checkResourceParam($resource);
$this
->checkSinglePropertyParam($property, $inverse);
if (is_array($value)) {
$added = 0;
foreach ($value as $v) {
$added += $this
->addLiteral($resource, $property, $v, $lang);
}
return $added;
}
else {
if ($lang) {
$value = array(
'type' => 'literal',
'value' => $value,
'lang' => $lang,
);
}
else {
$value = array(
'type' => 'literal',
'value' => $value,
'datatype' => EasyRdf_Literal::getDatatypeForValue($value),
);
if (empty($value['datatype'])) {
unset($value['datatype']);
}
}
return $this
->add($resource, $property, $value);
}
}