1 | <?php |
||
8 | class ResultIterator implements \Iterator { |
||
9 | /** |
||
10 | * Stream containing the raw result data |
||
11 | * |
||
12 | * @var StreamReader |
||
13 | */ |
||
14 | private $stream; |
||
15 | |||
16 | /** |
||
17 | * Offset to start reading data in this stream |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | private $offset; |
||
22 | |||
23 | /** |
||
24 | * Metadata generated by the creating Result |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | private $metadata; |
||
29 | |||
30 | /** |
||
31 | * Class to use for each row of data |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $rowClass; |
||
36 | |||
37 | /** |
||
38 | * Number of available rows in the resultset |
||
39 | * |
||
40 | * @var int |
||
41 | */ |
||
42 | private $count; |
||
43 | |||
44 | /** |
||
45 | * Current row |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | private $row = 0; |
||
50 | |||
51 | |||
52 | public function __construct(StreamReader $stream, array $metadata, $rowClass) { |
||
|
|||
53 | $this->stream = clone $stream; |
||
54 | $this->metadata = $metadata; |
||
55 | $this->count = $this->stream->readInt(); |
||
56 | $this->offset = $this->stream->pos(); |
||
57 | $this->rewind(); |
||
58 | } |
||
59 | |||
60 | public function current() { |
||
61 | $data = []; |
||
62 | |||
63 | foreach ($this->metadata['columns'] as $column) { |
||
64 | $data[$column['name']] = $this->stream->readValue($column['type']); |
||
65 | } |
||
66 | |||
67 | $rowClass = $this->rowClass; |
||
68 | return ($rowClass === null ? $data : new $rowClass($data)); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * The current position in this result set |
||
73 | * |
||
74 | * @return int |
||
75 | */ |
||
76 | public function key() { |
||
79 | |||
80 | /** |
||
81 | * Move forward to next element |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | public function next() { |
||
88 | |||
89 | /** |
||
90 | * Reset the result set |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | public function rewind() { |
||
98 | |||
99 | /** |
||
100 | * Checks if current position is valid |
||
101 | * |
||
102 | * @return boolean |
||
103 | */ |
||
104 | public function valid() { |
||
107 | } |
||
108 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.