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.
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:
boolean True if value the property exists.
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;
}