public function EasyRdf_Graph::resourcesMatching

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

Parameters

string $property The property to check.:

mixed $value Optional, the value of the propery to check for.:

Return value

array Array of EasyRdf_Resource

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php, line 372

Class

EasyRdf_Graph
Container for collection of EasyRdf_Resources.

Code

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;
}