1 | <?php namespace Spaark\CompositeUtils\Model\Collection; |
||
26 | class Collection implements \ArrayAccess, \Iterator, \Countable |
||
27 | { |
||
28 | /** |
||
29 | * The raw data of this Collection |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $data = array( ); |
||
34 | |||
35 | /** |
||
36 | * The current position of the array pointer |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $pointer = 0; |
||
41 | |||
42 | /** |
||
43 | * Returns the current element |
||
44 | * |
||
45 | * @return mixed The current element |
||
46 | */ |
||
47 | public function current() |
||
51 | |||
52 | /** |
||
53 | * Returns the current key |
||
54 | * |
||
55 | * @return int The current key |
||
56 | */ |
||
57 | public function key() |
||
61 | |||
62 | /** |
||
63 | * Advances the internal pointer by one |
||
64 | */ |
||
65 | public function next() |
||
71 | |||
72 | /** |
||
73 | * Checks if the given offset is set |
||
74 | * |
||
75 | * @param scalar $offset The offset to check |
||
76 | * @return boolean True if the offset is set |
||
77 | */ |
||
78 | 7 | public function offsetExists($offset) |
|
79 | { |
||
80 | 7 | return isset($this->data[$offset]); |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Returns the data at the given offset |
||
85 | * |
||
86 | * @param scalar $offset The offset to get |
||
87 | * @return mixed The value at the given offset |
||
88 | */ |
||
89 | 8 | public function offsetGet($offset) |
|
90 | { |
||
91 | 8 | return $this->data[$offset]; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Adds a new key-value pair to the Collection |
||
96 | * |
||
97 | * If the key already exists in the collection, its key-value is |
||
98 | * overwritten. |
||
99 | * |
||
100 | * @param scalar $offset The key to set |
||
101 | * @param mixed $value The value to set |
||
102 | */ |
||
103 | 2 | public function offsetSet($offset, $value) |
|
104 | { |
||
105 | 2 | $this->data[$offset] = $value; |
|
106 | 2 | } |
|
107 | |||
108 | /** |
||
109 | * Removes the given key-value pair from the Collection |
||
110 | * |
||
111 | * @param scalar $offset The key to unset |
||
112 | */ |
||
113 | public function offsetUnset($offset) |
||
117 | |||
118 | /** |
||
119 | * Resets the internal array pointer |
||
120 | */ |
||
121 | public function rewind() |
||
127 | |||
128 | /** |
||
129 | * Changes the position of the array pointer |
||
130 | * |
||
131 | * @param scalar $pos The position to seek to |
||
132 | * @return mixed The value at that new point |
||
133 | */ |
||
134 | public function seek($pos) |
||
140 | |||
141 | /** |
||
142 | * Checks if there are any more elements to be read from the |
||
143 | * Collection |
||
144 | * |
||
145 | * @return boolean True if there are one or more elements |
||
146 | */ |
||
147 | public function valid() |
||
151 | |||
152 | /** |
||
153 | * Adds an element to the Collection, without specifying a key |
||
154 | * |
||
155 | * @param scalar $offset The key to set |
||
156 | * @param mixed $item The element to add |
||
157 | */ |
||
158 | 9 | public function add($offset, $item) |
|
162 | |||
163 | /** |
||
164 | * Push an element onto the end of the array |
||
165 | * |
||
166 | * @param mixed $item The element to add |
||
167 | */ |
||
168 | 6 | public function push($item) |
|
172 | |||
173 | /** |
||
174 | * Returns how many elements are in the Collection |
||
175 | * |
||
176 | * @return int The number of elements in the Collection |
||
177 | */ |
||
178 | 9 | public function size() |
|
182 | |||
183 | /** |
||
184 | * Returns how many elements are in the Collection |
||
185 | * |
||
186 | * @return int The number of elements in the Collection |
||
187 | */ |
||
188 | 4 | public function count() |
|
192 | |||
193 | /** |
||
194 | * Checks if the Collection is empty |
||
195 | * |
||
196 | * @return boolean True if the element is empty |
||
197 | */ |
||
198 | 2 | public function empty() |
|
202 | |||
203 | /** |
||
204 | * Clears the Collection of all data |
||
205 | */ |
||
206 | public function clear() |
||
210 | |||
211 | /** |
||
212 | * Magic Method which returns the Collection's data when it is |
||
213 | * passed to var_dump or similar |
||
214 | * |
||
215 | * This prevents the Collection from returning the large amount of |
||
216 | * extra stuff that is contained within Collection, such as the |
||
217 | * internal pointer and inherited interanal Model elements. |
||
218 | * |
||
219 | * @return array The data |
||
220 | */ |
||
221 | public function __debugInfo() |
||
225 | } |
||
226 |