summaryrefslogtreecommitdiff
path: root/lib/querypath/src/QueryPath/QueryPathIterator.php
blob: be2e66f0e3137f8d943688a1632574ba9742aaee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
 * @file
 *
 * Utility iterator for QueryPath.
 */
namespace QueryPath;

/**
 * An iterator for QueryPath.
 *
 * This provides iterator support for QueryPath. You do not need to construct
 * a QueryPathIterator. QueryPath does this when its QueryPath::getIterator()
 * method is called.
 *
 * @ingroup querypath_util
 */
class QueryPathIterator extends \IteratorIterator {
  public $options = array();
  private $qp = NULL;

  public function current() {
    if (!isset($this->qp)) {
      $this->qp = \QueryPath::with(parent::current(), NULL, $this->options);
    }
    else {
      $splos = new \SplObjectStorage();
      $splos->attach(parent::current());
      $this->qp->setMatches($splos);
    }
    return $this->qp;
  }
}