You are here

public function QueryPath::has in QueryPath 7.2

Same name and namespace in other branches
  1. 6 QueryPath/QueryPath.php \QueryPath::has()
  2. 7.3 QueryPath/QueryPath.php \QueryPath::has()

File

QueryPath/QueryPath.php, line 1614

Class

QueryPath

Code

public function has($contained) {
  $found = new SplObjectStorage();
  $nodes = array();
  if (is_string($contained)) {
    $nodes = $this
      ->branch($contained)
      ->get();
  }
  elseif ($contained instanceof DOMNode) {
    $nodes = array(
      $contained,
    );
  }
  foreach ($nodes as $original_node) {
    $node = $original_node;
    while (!empty($node)) {
      if ($this->matches
        ->contains($node)) {
        $found
          ->attach($node);
      }
      $node = $node->parentNode;
    }
  }
  $this
    ->setMatches($found);
  return $this;
}