You are here

public function QueryPath::peers in QueryPath 6

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

File

QueryPath/QueryPath.php, line 1506

Class

QueryPath

Code

public function peers($selector = NULL) {
  $found = new SplObjectStorage();
  foreach ($this->matches as $m) {
    foreach ($m->parentNode->childNodes as $kid) {
      if ($kid->nodeType == XML_ELEMENT_NODE && $m !== $kid) {
        if (!empty($selector)) {
          if (qp($kid, NULL, $this->options)
            ->is($selector)) {
            $found
              ->attach($kid);
          }
        }
        else {
          $found
            ->attach($kid);
        }
      }
    }
  }
  $this
    ->setMatches($found);
  return $this;
}