Get an arry of resources matching a certain property and optional value.
For example this routine could be used as a way of getting everyone who has name: $people = $graph->resourcesMatching('foaf:name')
Or everyone who is male: $people = $graph->resourcesMatching('foaf:gender', 'male');
Or all homepages: $people = $graph->resourcesMatching('^foaf:homepage');
string $property The property to check.:
mixed $value Optional, the value of the propery to check for.:
array Array of EasyRdf_Resource
public function resourcesMatching($property, $value = null) {
$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;
}
$matched = array();
foreach ($index as $subject => $props) {
if (isset($index[$subject][$property])) {
if (isset($value)) {
foreach ($this->index[$subject][$property] as $v) {
if ($v['type'] == $value['type'] and $v['value'] == $value['value']) {
$matched[] = $this
->resource($subject);
break;
}
}
}
else {
$matched[] = $this
->resource($subject);
}
}
}
return $matched;
}