1 | <?php |
||
46 | class Collection implements CollectionInterface |
||
47 | { |
||
48 | /** |
||
49 | * Objects |
||
50 | * |
||
51 | * @var ObjectInterface[]|RepositoryPath[] |
||
52 | */ |
||
53 | protected $_objects = array(); |
||
54 | /** |
||
55 | * Object IDs |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $_objectIds = array(); |
||
60 | /** |
||
61 | * Internal object pointer |
||
62 | * |
||
63 | * @var int |
||
64 | */ |
||
65 | protected $_pointer = 0; |
||
66 | |||
67 | /******************************************************************************* |
||
68 | * PUBLIC METHODS |
||
69 | *******************************************************************************/ |
||
70 | |||
71 | /** |
||
72 | * Collection constructor |
||
73 | * |
||
74 | * @param array $objects Collection objects |
||
75 | * @throws InvalidArgumentException If the an invalid object or path is provided |
||
76 | */ |
||
77 | 7 | public function __construct(array $objects = []) |
|
99 | |||
100 | /** |
||
101 | * Return the current object |
||
102 | * |
||
103 | * @return ObjectInterface Current object |
||
104 | */ |
||
105 | 3 | public function current() |
|
109 | |||
110 | /** |
||
111 | * Load and return an object by ID |
||
112 | * |
||
113 | * @param int $objectId Object ID |
||
114 | * @return ObjectInterface Object |
||
115 | */ |
||
116 | 3 | protected function _loadObject($objectId) |
|
127 | |||
128 | /** |
||
129 | * Move forward to next object |
||
130 | * |
||
131 | * @return void |
||
132 | */ |
||
133 | 1 | public function next() |
|
137 | |||
138 | /** |
||
139 | * Return the ID of the current object |
||
140 | * |
||
141 | * @return int Object ID |
||
142 | */ |
||
143 | 1 | public function key() |
|
147 | |||
148 | /** |
||
149 | * Checks if current position is valid |
||
150 | * |
||
151 | * @return boolean The current position is valid |
||
152 | */ |
||
153 | 3 | public function valid() |
|
157 | |||
158 | /** |
||
159 | * Rewind the Iterator to the first object |
||
160 | * |
||
161 | * @return void |
||
162 | */ |
||
163 | 3 | public function rewind() |
|
167 | |||
168 | /** |
||
169 | * Whether an object ID exists |
||
170 | * |
||
171 | * @param int $offset Object ID |
||
172 | * @return boolean Whether the object ID exists |
||
173 | */ |
||
174 | 1 | public function offsetExists($offset) |
|
178 | |||
179 | /** |
||
180 | * Get an object with a particular ID |
||
181 | * |
||
182 | * @param int $offset Object ID |
||
183 | * @return ObjectInterface Object |
||
184 | */ |
||
185 | 2 | public function offsetGet($offset) |
|
189 | |||
190 | /** |
||
191 | * Set an object by ID |
||
192 | * |
||
193 | * @param int $offset Object ID |
||
194 | * @param ObjectInterface $value Object |
||
195 | * @throws RuntimeException When an object should be set by ID |
||
196 | */ |
||
197 | 1 | public function offsetSet($offset, $value) |
|
201 | |||
202 | /** |
||
203 | * Unset an object by ID |
||
204 | * |
||
205 | * @param int $offset Object ID |
||
206 | * @throws RuntimeException When an object should be set by ID |
||
207 | */ |
||
208 | 1 | public function offsetUnset($offset) |
|
212 | |||
213 | /** |
||
214 | * Add an object to the collection |
||
215 | * |
||
216 | * @param string|ObjectInterface $object Object or object URL |
||
217 | * @return Collection Modified object collection |
||
218 | */ |
||
219 | 2 | public function add($object) |
|
225 | |||
226 | /** |
||
227 | * Remove an object out of this collection |
||
228 | * |
||
229 | * @param string|ObjectInterface $object Object or object ID |
||
230 | * @return Collection Modified object collection |
||
231 | */ |
||
232 | 1 | public function remove($object) |
|
250 | |||
251 | /** |
||
252 | * Count objects in this collection |
||
253 | * |
||
254 | * @return int The number of objects in this collection |
||
255 | */ |
||
256 | 6 | public function count() |
|
260 | |||
261 | /******************************************************************************* |
||
262 | * PRIVATE METHODS |
||
263 | *******************************************************************************/ |
||
264 | |||
265 | /** |
||
266 | * Append another collection |
||
267 | * |
||
268 | * @param Collection $collection Collection |
||
269 | * @return Collection Combined collections |
||
270 | */ |
||
271 | 1 | public function append(Collection $collection) |
|
276 | } |
||
277 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.