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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
<?php
/* $Id: PhDPartialReader.class.php 260232 2008-05-24 14:49:14Z gwynne $ */
class PhDPartialReader extends PhDReader {
protected $partial = array();
protected $skip = array();
public function __construct($opts, $encoding = "UTF-8", $xml_opts = NULL) {
parent::__construct($opts, $encoding, $xml_opts);
if (isset($opts["render_ids"])) {
if (is_array($opts["render_ids"])) {
$this->partial = $opts["render_ids"];
} else {
$this->partial[$opts["render_ids"]] = 1;
}
if (isset($opts["skip_ids"])) {
if (is_array($opts["skip_ids"])) {
$this->skip = $opts["skip_ids"];
} else {
$this->skip[$opts["skip_ids"]] = 1;
}
}
} else {
throw new Exception("Didn't get any IDs to seek");
}
}
public function read() {
static $seeked = 0;
static $currently_reading = false;
static $currently_skipping = false;
$ignore = false;
while($ret = parent::read()) {
if ($this->isChunk) {
$id = $this->getAttributeNs("id", PhDReader::XMLNS_XML);
if (isset($this->partial[$id])) {
if ($this->isChunk == PhDReader::CLOSE_CHUNK) {
v("%s done", $id, VERBOSE_PARTIAL_READING);
unset($this->partial[$id]);
--$seeked;
$currently_reading = false;
} else {
v("Starting %s...", $id, VERBOSE_PARTIAL_READING);
$currently_reading = $id;
++$seeked;
}
return $ret;
} elseif (isset($this->skip[$id])) {
if ($this->isChunk == PhDReader::CLOSE_CHUNK) {
v("%s done", $id, VERBOSE_PARTIAL_READING);
unset($this->skip[$id]);
$currently_skipping = false;
$ignore = false;
} else {
v("Skipping %s...", $id, VERBOSE_PARTIAL_READING);
$currently_skipping = $id;
$ignore = true;
}
} elseif ($currently_skipping && $this->skip[$currently_skipping]) {
if ($this->isChunk == PhDReader::OPEN_CHUNK) {
v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING);
} else {
v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING);
}
$ignore = true;
} elseif ($currently_reading && $this->partial[$currently_reading]) {
if ($this->isChunk == PhDReader::OPEN_CHUNK) {
v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING);
} else {
v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING);
}
return $ret;
} elseif (empty($this->partial)) {
return false;
} else {
$ignore = true;
}
} elseif (!$ignore && $seeked > 0) {
return $ret;
}
}
return $ret;
}
}
/*
* vim600: sw=4 ts=4 fdm=syntax syntax=php et
* vim<600: sw=4 ts=4
*/
|