1 | <?php |
||
33 | class LDAPResultIterator implements SeekableIterator, Countable { |
||
34 | |||
35 | var $list; |
||
36 | var $key; |
||
37 | var $valid; |
||
38 | protected $ldapParams; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | */ |
||
43 | function __construct($info, $ldapParams) { |
||
44 | $this->list = $info; |
||
45 | $this->key = 0; |
||
46 | $this->valid = ($this->count() > 0); |
||
47 | $this->ldapParams = $ldapParams; |
||
48 | } |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Return the number of entries in a result set. |
||
53 | * |
||
54 | * @return int |
||
55 | */ |
||
56 | function count() { |
||
57 | if($this->list && array_key_exists('count', $this->list)){ |
||
58 | return $this->list['count']; |
||
59 | } |
||
60 | else { |
||
61 | return 0; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Return true if there is no entries in the result set. |
||
68 | * |
||
69 | * @return int |
||
70 | */ |
||
71 | function isEmpty() { |
||
74 | |||
75 | |||
76 | /** |
||
77 | * Move key to the position given in parameter. |
||
78 | * |
||
79 | * @param $pos int |
||
80 | */ |
||
81 | function seek($pos) { |
||
82 | $this->key = $pos; |
||
83 | $this->valid = true; |
||
84 | if($this->key >= $this->count()) { |
||
85 | $this->valid = false; |
||
86 | } |
||
87 | if($this->key < 0) { |
||
88 | $this->valid = false; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Move key to the position given in parameter. |
||
95 | * |
||
96 | * @param $pos int |
||
97 | */ |
||
98 | function get($pos) { |
||
99 | $this->seek($pos); |
||
100 | if($this->valid) { |
||
101 | return $this->current(); |
||
102 | } |
||
103 | else { |
||
104 | return false; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Return true if result set is not empty. |
||
111 | * |
||
112 | * @return boolean |
||
113 | */ |
||
114 | function exist() { |
||
117 | |||
118 | |||
119 | /** |
||
120 | * Return the current element. |
||
121 | * |
||
122 | * Standard function implemented from Iterator interface |
||
123 | * |
||
124 | * @return LDAPResult |
||
125 | */ |
||
126 | function current() { |
||
129 | |||
130 | |||
131 | /** |
||
132 | * Return the key of the current element. |
||
133 | * |
||
134 | * Standard function implemented from Iterator interface |
||
135 | * |
||
136 | * @return int |
||
137 | */ |
||
138 | function key() { |
||
141 | |||
142 | |||
143 | /** |
||
144 | * Move forward to next element. |
||
145 | * |
||
146 | * Standard function implemented from Iterator interface |
||
147 | */ |
||
148 | function next() { |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Rewind the Iterator to the first element. |
||
155 | * |
||
156 | * Standard function implemented from Iterator interface |
||
157 | */ |
||
158 | function rewind() { |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Check if there is a current element after calls to rewind() or next(). |
||
166 | * |
||
167 | * Standard function implemented from Iterator interface |
||
168 | * |
||
169 | * @return boolean |
||
170 | */ |
||
171 | function valid() { |
||
174 | } |
||
175 | |||
176 | |||
177 | |||
178 | /** |
||
302 | ?> |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.