public function find($selector)
{
// Setup
$handler = new Selector();
$parser = new Parser($selector, $handler);
$parser->parse();
$this->selector = $handler;
//$selector = $handler->toArray();
$found = $this->newMatches();
foreach ($handler as $selectorGroup) {
// fprintf(STDOUT, "Selector group.\n");
// Initialize matches if necessary.
if ($this->initialized) {
$candidates = $this->matches;
} else {
//if (empty($selectorGroup)) {
// fprintf(STDOUT, "%s", print_r($handler->toArray(), TRUE));
//}
$candidates = $this->initialMatch($selectorGroup[0], $this->matches);
//$this->initialized = TRUE;
}
foreach ($candidates as $candidate) {
// fprintf(STDOUT, "Testing %s against %s.\n", $candidate->tagName, $selectorGroup[0]);
if ($this->matchesSelector($candidate, $selectorGroup)) {
// $this->debug('Attaching ' . $candidate->nodeName);
$found->attach($candidate);
}
}
}
$this->setMatches($found);
return $this;
}