-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuerySetResultIterator.php
134 lines (104 loc) · 2.28 KB
/
QuerySetResultIterator.php
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* PerfORM - Object-relational mapping based on David Grudl's dibi
*
* @copyright Copyright (c) 2010 Eduard 'edke' Kracmar
* @license no license set at this point
* @link http://perform.local :-)
* @category QuerySet
* @package PerfORM
*/
/**
* QuerySetResultIterator
*
* ....
*
* @final
* @copyright Copyright (c) 2010 Eduard 'edke' Kracmar
* @package PerfORM
*/
class QuerySetResultIterator implements Iterator, Countable
{
/**
* @var QuerySetResult
*/
protected $result;
/** @var int */
protected $offset;
/** @var int */
protected $limit;
/** @var int */
protected $row;
/** @var int */
protected $pointer;
/**
* @var boolean
*/
protected $profiler;
public function __construct(QuerySetResult $result, $offset = NULL, $limit = NULL)
{
$this->result= $result;
$this->offset = (int) $offset;
$this->limit = $limit === NULL ? -1 : (int) $limit;
//$this->profiler= Environment::getConfig('perform')->profiler;
}
/**
* Rewinds the iterator to the first element.
* @return void
*/
public function rewind()
{
$this->pointer = 0;
$this->result->seek($this->offset);
$this->row = $this->result->fetch();
}
/**
* Returns the key of the current element.
* @return mixed
*/
public function key()
{
return $this->pointer;
}
/**
* Returns the current element.
* @return mixed
*/
public function current()
{
$modelName= $this->result->getModelName();
$model = new $modelName;
$model->fill($this->row);
//$this->profiler();
return $model;
}
/**
* Moves forward to next element.
* @return void
*/
public function next()
{
$this->row = $this->result->fetch();
$this->pointer++;
}
/**
* Checks if there is a current element after calls to rewind() or next().
* @return bool
*/
public function valid()
{
return !empty($this->row) && ($this->limit < 0 || $this->pointer < $this->limit);
}
final public function count()
{
return $this->result->count();
}
protected function profiler()
{
if ( $this->profiler)
{
PerfORMController::addSql(dibi::$sql);
$this->profiler= false;
}
}
}