You are here

public function EasyRdf_Graph::hasProperty in Zircon Profile 8

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

Check to see if a property exists for a resource.

This method will return true if the property exists. If the value parameter is given, then it will only return true if the value also exists for that property.

By providing a value parameter you can use this function to check to see if a triple exists in the graph.

Parameters

mixed $resource The resource to check:

string $property The name of the property (e.g. foaf:name):

mixed $value An optional value of the property:

Return value

boolean True if value the property exists.

1 call to EasyRdf_Graph::hasProperty()
EasyRdf_Graph::__isset in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Magic method to check if a property exists

File

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

Class

EasyRdf_Graph
Container for collection of EasyRdf_Resources.

Code

public function hasProperty($resource, $property, $value = null) {
  $this
    ->checkResourceParam($resource);
  $this
    ->checkSinglePropertyParam($property, $inverse);
  $this
    ->checkValueParam($value);

  // Use the reverse index if it is an inverse property
  if ($inverse) {
    $index =& $this->revIndex;
  }
  else {
    $index =& $this->index;
  }
  if (isset($index[$resource][$property])) {
    if (is_null($value)) {
      return true;
    }
    else {
      foreach ($index[$resource][$property] as $v) {
        if ($v == $value) {
          return true;
        }
      }
    }
  }
  return false;
}