1 | <?php |
||
20 | class Collection |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * The collection data. |
||
25 | * @var array |
||
26 | */ |
||
27 | private $items = []; |
||
28 | |||
29 | /** |
||
30 | * Create new instance of a Collection. |
||
31 | * @param array $items |
||
32 | */ |
||
33 | 26 | public function __construct($items = null) |
|
39 | |||
40 | /** |
||
41 | * Resets the collection with the specified array content. |
||
42 | * @param array $items |
||
43 | * @return Collection |
||
44 | */ |
||
45 | 2 | public function reset($items = null) |
|
54 | |||
55 | /** |
||
56 | * Set an item or items into the the collection. |
||
57 | * @param mixed $key |
||
58 | * @param mixed $item |
||
59 | * @return Collection |
||
60 | */ |
||
61 | 1 | public function put($key, $item) |
|
66 | |||
67 | /** |
||
68 | * Push a new item (or array of items) into the collection onto the end |
||
69 | * of the collection. |
||
70 | * @param mixed $item |
||
71 | * @return Collection |
||
72 | */ |
||
73 | 25 | public function push($item) |
|
82 | |||
83 | /** |
||
84 | * Push an item (or array of items) onto the beginning of the collection. |
||
85 | * @param mixed $item |
||
86 | * @return Collection |
||
87 | */ |
||
88 | 1 | public function prepend($item) |
|
93 | |||
94 | /** |
||
95 | * Get and remove the first item from the collection. |
||
96 | * @return mixed |
||
97 | */ |
||
98 | 1 | public function shift() |
|
102 | |||
103 | /** |
||
104 | * Pops an item off the end of the collection. |
||
105 | * @return Collection |
||
106 | */ |
||
107 | 1 | public function pop() |
|
112 | |||
113 | /** |
||
114 | * Get all items from the collection. |
||
115 | * @return CollectionExport |
||
116 | */ |
||
117 | 7 | public function all() |
|
121 | |||
122 | /** |
||
123 | * Checks if the collection has a the specified key set. |
||
124 | * @param mixed $key The key name to check if it exists. |
||
125 | * @return boolean |
||
126 | */ |
||
127 | 4 | public function has($key) |
|
131 | |||
132 | /** |
||
133 | * Get a specific item from the collection. |
||
134 | * @param string $key The collection (array) key to return. |
||
135 | * @param string $default Optional default value if the key doesn't exist (defaulted to false) |
||
136 | * @return string |
||
137 | */ |
||
138 | 2 | public function get($key, $default = false) |
|
145 | |||
146 | /** |
||
147 | * The total number of items in the collection. |
||
148 | * @return int |
||
149 | */ |
||
150 | 6 | public function count() |
|
154 | |||
155 | /** |
||
156 | * Iterate over each of the items in the collection and execute the callback. |
||
157 | * @param callable $callback |
||
158 | * @return Collection |
||
159 | */ |
||
160 | 2 | public function each(callable $callback) |
|
169 | |||
170 | /** |
||
171 | * Return the first item in the collection. |
||
172 | * @return mixed |
||
173 | */ |
||
174 | 1 | public function first() |
|
178 | |||
179 | /** |
||
180 | * Returns the last item in the collection. |
||
181 | * @return mixed |
||
182 | */ |
||
183 | 1 | public function last() |
|
187 | |||
188 | /** |
||
189 | * Shuffles (randomises) the items in the collection. |
||
190 | * @return Collection |
||
191 | */ |
||
192 | 1 | public function shuffle() |
|
197 | |||
198 | /** |
||
199 | * Converts the colletion into a string. |
||
200 | * @return string |
||
201 | */ |
||
202 | 1 | public function implode($glue = ' ') |
|
206 | |||
207 | /** |
||
208 | * Checks to see if the collection is empty. |
||
209 | * @return boolean |
||
210 | */ |
||
211 | 2 | public function isEmpty() |
|
215 | |||
216 | /** |
||
217 | * Get an iterator for the collection. |
||
218 | * @return \ArrayIterator |
||
219 | */ |
||
220 | 1 | public function getIterator() |
|
224 | |||
225 | /** |
||
226 | * Converts the collection to it's string representation (JSON) |
||
227 | * @return string |
||
228 | */ |
||
229 | 1 | public function __toString() |
|
233 | |||
234 | /** |
||
235 | * Converts the collection to JSON. |
||
236 | * @return string |
||
237 | */ |
||
238 | 1 | public function toJson() |
|
242 | } |
||
243 |