Remove product literal strings in "pht()", part 5
[phabricator.git] / src / applications / files / engine / PhabricatorFileChunkIterator.php
blob50b605dc95f629b0d8b3fd4f3409f74079cf212f
1 <?php
3 final class PhabricatorFileChunkIterator
4 extends Phobject
5 implements Iterator {
7 private $chunks;
8 private $cursor;
9 private $begin;
10 private $end;
11 private $data;
13 public function __construct(array $chunks, $begin = null, $end = null) {
14 $chunks = msort($chunks, 'getByteStart');
15 $this->chunks = $chunks;
17 if ($begin !== null) {
18 foreach ($chunks as $key => $chunk) {
19 if ($chunk->getByteEnd() >= $begin) {
20 unset($chunks[$key]);
22 break;
24 $this->begin = $begin;
27 if ($end !== null) {
28 foreach ($chunks as $key => $chunk) {
29 if ($chunk->getByteStart() <= $end) {
30 unset($chunks[$key]);
33 $this->end = $end;
37 public function current() {
38 $chunk = head($this->chunks);
39 $data = $chunk->getDataFile()->loadFileData();
41 if ($this->end !== null) {
42 if ($chunk->getByteEnd() > $this->end) {
43 $data = substr($data, 0, ($this->end - $chunk->getByteStart()));
47 if ($this->begin !== null) {
48 if ($chunk->getByteStart() < $this->begin) {
49 $data = substr($data, ($this->begin - $chunk->getByteStart()));
53 return $data;
56 public function key() {
57 return head_key($this->chunks);
60 public function next() {
61 unset($this->chunks[$this->key()]);
64 public function rewind() {
65 return;
68 public function valid() {
69 return (count($this->chunks) > 0);