You are here

public function QueryPath::wrapAll in QueryPath 6

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

File

QueryPath/QueryPath.php, line 793

Class

QueryPath

Code

public function wrapAll($markup) {
  if ($this->matches
    ->count() == 0) {
    return;
  }
  $data = $this
    ->prepareInsert($markup);
  if (empty($data)) {
    return $this;
  }
  if ($data
    ->hasChildNodes()) {
    $deepest = $this
      ->deepestNode($data);
    $bottom = $deepest[0];
  }
  else {
    $bottom = $data;
  }
  $first = $this
    ->getFirstMatch();
  $parent = $first->parentNode;
  $parent
    ->insertBefore($data, $first);
  foreach ($this->matches as $m) {
    $bottom
      ->appendChild($m->parentNode
      ->removeChild($m));
  }
  return $this;
}