You are here

public function EasyRdf_Graph::addLiteral in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php \EasyRdf_Graph::addLiteral()

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');

Parameters

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:

Return value

integer The number of values added

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php, line 966

Class

EasyRdf_Graph
Container for collection of EasyRdf_Resources.

Code

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;
  }
  elseif (!is_object($value) or !$value instanceof EasyRdf_Literal) {
    $value = EasyRdf_Literal::create($value, $lang);
  }
  return $this
    ->add($resource, $property, $value);
}