Skip to content

Commit

Permalink
Allow using SelectorDOM on existing DOMDocument object
Browse files Browse the repository at this point in the history
Instead of creating a new DOMDocument, allow passing of DOMDocument object. In this way the returned nodes will reference the original document. Also removed saving the $html and $dom as instance variables, since they are not used
  • Loading branch information
Darhazer committed Jul 30, 2013
1 parent 6eab940 commit c93001a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions selector.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ define('SELECTOR_VERSION', '1.1.3');
*/

class SelectorDOM {
public function SelectorDOM($html) {
$this->html = $html;
$this->dom = new DOMDocument();
@$this->dom->loadHTML($html);
$this->xpath = new DOMXpath($this->dom);
public function SelectorDOM($data) {
if ($data instanceof DOMDocument) {
$this->xpath = new DOMXpath($data);
} else {
$dom = new DOMDocument();
@$dom->loadHTML($data);
$this->xpath = new DOMXpath($dom);
}
}

public function select($selector, $as_array = true) {
Expand Down Expand Up @@ -125,4 +128,4 @@ function selector_to_xpath($selector) {
$selector = str_replace(']*', ']', $selector);
$selector = str_replace(']/*', ']', $selector);
return $selector;
}
}

0 comments on commit c93001a

Please sign in to comment.