1 | <?php |
||
40 | class Collection implements \ArrayAccess, \Iterator, \Countable |
||
41 | { |
||
42 | /** |
||
43 | * The raw data of this Collection |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $data = array( ); |
||
48 | |||
49 | /** |
||
50 | * The current position of the array pointer |
||
51 | * |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $pointer = 0; |
||
55 | |||
56 | /** |
||
57 | * Returns the current element |
||
58 | * |
||
59 | * @return mixed The current element |
||
60 | */ |
||
61 | 8 | public function current() |
|
62 | { |
||
63 | 8 | return $this->offsetGet($this->pointer); |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Returns the current key |
||
68 | * |
||
69 | * @return int The current key |
||
70 | */ |
||
71 | public function key() |
||
75 | |||
76 | /** |
||
77 | * Advances the internal pointer by one |
||
78 | */ |
||
79 | 6 | public function next() |
|
80 | { |
||
81 | 6 | $this->pointer++; |
|
82 | |||
83 | 6 | return $this->valid() ? $this->offsetGet($this->pointer) : null; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * Checks if the given offset is set |
||
88 | * |
||
89 | * @param scalar $offset The offset to check |
||
90 | * @return boolean True if the offset is set |
||
91 | */ |
||
92 | public function offsetExists($offset) |
||
93 | { |
||
94 | return isset($this->data[$offset]); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Returns the data at the given offset |
||
99 | * |
||
100 | * @param scalar $offset The offset to get |
||
101 | * @return mixed The value at the given offset |
||
102 | */ |
||
103 | 9 | public function offsetGet($offset) |
|
107 | |||
108 | /** |
||
109 | * Adds a new key-value pair to the Collection |
||
110 | * |
||
111 | * If the key already exists in the collection, its key-value is |
||
112 | * overwritten. |
||
113 | * |
||
114 | * @param scalar $offset The key to set |
||
115 | * @param mixed $value The value to set |
||
116 | */ |
||
117 | 21 | public function offsetSet($offset, $value) |
|
121 | |||
122 | /** |
||
123 | * Removes the given key-value pair from the Collection |
||
124 | * |
||
125 | * @param scalar $offset The key to unset |
||
126 | */ |
||
127 | public function offsetUnset($offset) |
||
131 | |||
132 | /** |
||
133 | * Resets the internal array pointer |
||
134 | */ |
||
135 | 8 | public function rewind() |
|
139 | |||
140 | /** |
||
141 | * Changes the position of the array pointer |
||
142 | * |
||
143 | * @param scalar $pos The position to seek to |
||
144 | * @return mixed The value at that new point |
||
145 | */ |
||
146 | public function seek($pos) |
||
152 | |||
153 | /** |
||
154 | * Checks if there are any more elements to be read from the |
||
155 | * Collection |
||
156 | * |
||
157 | * @return boolean True if there are one or more elements |
||
158 | */ |
||
159 | 8 | public function valid() |
|
163 | |||
164 | /** |
||
165 | * Adds an element to the Collection, without specifying a key |
||
166 | * |
||
167 | * @param scalar $offset The key to set |
||
168 | * @param mixed $item The element to add |
||
169 | */ |
||
170 | public function add($offset, $item) |
||
174 | |||
175 | /** |
||
176 | * Push an element onto the end of the array |
||
177 | * |
||
178 | * @param mixed $item The element to add |
||
179 | */ |
||
180 | 21 | public function push($item) |
|
184 | |||
185 | /** |
||
186 | * Returns how many elements are in the Collection |
||
187 | * |
||
188 | * @return int The number of elements in the Collection |
||
189 | */ |
||
190 | 24 | public function size() |
|
194 | |||
195 | /** |
||
196 | * Returns how many elements are in the Collection |
||
197 | * |
||
198 | * @return int The number of elements in the Collection |
||
199 | */ |
||
200 | 1 | public function count() |
|
204 | |||
205 | /** |
||
206 | * Checks if the Collection is empty |
||
207 | * |
||
208 | * @return boolean True if the element is empty |
||
209 | */ |
||
210 | 2 | public function empty() |
|
214 | |||
215 | /** |
||
216 | * Clears the Collection of all data |
||
217 | */ |
||
218 | public function clear() |
||
222 | |||
223 | /** |
||
224 | * Magic Method which returns the Collection's data when it is |
||
225 | * passed to var_dump or similar |
||
226 | * |
||
227 | * This prevents the Collection from returning the large amount of |
||
228 | * extra stuff that is contained within Collection, such as the |
||
229 | * internal pointer and inherited interanal Model elements. |
||
230 | * |
||
231 | * @return array The data |
||
232 | */ |
||
233 | public function __debugInfo() |
||
237 | } |
||
238 |