public function QueryPath::closest in QueryPath 6
Same name and namespace in other branches
- 7.3 QueryPath/QueryPath.php \QueryPath::closest()
- 7.2 QueryPath/QueryPath.php \QueryPath::closest()
File
- QueryPath/
QueryPath.php, line 1072
Class
Code
public function closest($selector) {
$found = new SplObjectStorage();
foreach ($this->matches as $m) {
if (qp($m, NULL, $this->options)
->is($selector) > 0) {
$found
->attach($m);
}
else {
while ($m->parentNode->nodeType !== XML_DOCUMENT_NODE) {
$m = $m->parentNode;
if ($m->nodeType === XML_ELEMENT_NODE && qp($m, NULL, $this->options)
->is($selector) > 0) {
$found
->attach($m);
break;
}
}
}
}
$this
->setMatches($found);
return $this;
}