hQuery.php
Context.php
1 <?php
2 namespace duzun\hQuery;
3 
4 // ------------------------------------------------------------------------
5 class_exists('duzun\\hQuery\\Node', false) or require_once __DIR__ . DIRECTORY_SEPARATOR . 'Node.php';
6 
7 // ------------------------------------------------------------------------
16 class Context extends Node {
17 
18  public function __construct($doc=NULL, $el_arr=NULL) {
19  if($el_arr instanceof parent) {
20  if(!$doc) $doc = $el_arr->doc();
21  $el_arr = $el_arr->ids;
22  }
23  elseif(is_array($el_arr)) {
24  ksort($el_arr);
25  }
26  parent::__construct($doc, $el_arr, true);
27  }
28 
34  public function intersect($el, $eq=true) {
35  if($el instanceof self) {
36  if($el === $this) {
37  if($eq) return $this;
38  else $el = array();
39  }
40  else {
41  $el = $el->ids;
42  }
43  }
44  else {
45  $el = $this->_ctx_ids($this->_doc_ids($el, true));
46  }
47  foreach($el as $b => $e) {
48  if(!$this->_has($b, $eq)) unset($el[$b]);
49  }
50 
51  return new self($el, $this->doc);
52  }
53 }
_ctx_ids($ids=NULL)
Definition: Node.php:256
_has($el, $eq=false)
$el < $this, with $eq == true -> $el <= $this
Definition: Node.php:567
_doc_ids($el, $force_array=true)
Definition: Node.php:299
intersect($el, $eq=true)
Definition: Context.php:34