You are here

public function QueryPath::parentsUntil in QueryPath 6

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

File

QueryPath/QueryPath.php, line 1792

Class

QueryPath

Code

public function parentsUntil($selector = NULL) {
  $found = new SplObjectStorage();
  foreach ($this->matches as $m) {
    while ($m->parentNode->nodeType !== XML_DOCUMENT_NODE) {
      $m = $m->parentNode;
      if ($m->nodeType === XML_ELEMENT_NODE) {
        if (!empty($selector)) {
          if (qp($m, NULL, $this->options)
            ->is($selector) > 0) {
            break;
          }
          else {
            $found
              ->attach($m);
          }
        }
        else {
          $found
            ->attach($m);
        }
      }
    }
  }
  $this
    ->setMatches($found);
  return $this;
}