1 | <?php namespace JobApis\Jobs\Client; |
||
9 | class Collection implements Countable |
||
10 | { |
||
11 | /** |
||
12 | * Items |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $items = []; |
||
17 | |||
18 | /** |
||
19 | * Errors |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $errors = []; |
||
24 | |||
25 | /** |
||
26 | * Add item to collection, at specific key if given |
||
27 | * |
||
28 | * @param mixed $item |
||
29 | * @param integer|string $key Optional |
||
30 | * |
||
31 | * @return Collection |
||
32 | */ |
||
33 | 28 | public function add($item, $key = null) |
|
47 | |||
48 | /** |
||
49 | * Append a collection to this collection. |
||
50 | * |
||
51 | * @param Collection $collection |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | 4 | public function addCollection(Collection $collection) |
|
72 | |||
73 | /** |
||
74 | * Add error to collection |
||
75 | * |
||
76 | * @param string $message |
||
77 | * |
||
78 | * @return Collection |
||
79 | */ |
||
80 | 14 | public function addError($message) |
|
90 | |||
91 | /** |
||
92 | * Get all items from collection |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | 8 | public function all() |
|
100 | |||
101 | /** |
||
102 | * Get count of items in collection |
||
103 | * |
||
104 | * @return integer |
||
105 | */ |
||
106 | 16 | public function count() |
|
110 | |||
111 | /** |
||
112 | * Delete item from collection at specific key |
||
113 | * |
||
114 | * @param integer|string $key |
||
115 | * |
||
116 | * @return Collection |
||
117 | */ |
||
118 | 4 | public function delete($key) |
|
128 | |||
129 | /** |
||
130 | * Filter items by a field having a specific value. |
||
131 | * |
||
132 | * @param string $field |
||
133 | * @param string $value |
||
134 | * @param string $operator |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | 4 | public function filter($field, $value, $operator = '=') |
|
159 | |||
160 | /** |
||
161 | * Get item from collection at specific key |
||
162 | * |
||
163 | * @param integer|string $key |
||
164 | * |
||
165 | * @return mixed |
||
166 | */ |
||
167 | 8 | public function get($key) |
|
177 | |||
178 | /** |
||
179 | * Get all errors from Collection |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | 14 | public function getErrors() |
|
187 | |||
188 | /** |
||
189 | * Order items by a field value. |
||
190 | * |
||
191 | * @param string $orderBy |
||
192 | * @param string $order |
||
193 | * |
||
194 | * @return $this |
||
195 | */ |
||
196 | 6 | public function orderBy($orderBy, $order = 'desc') |
|
219 | |||
220 | /** |
||
221 | * Truncate the items to a maximum number of results. |
||
222 | * |
||
223 | * @param null $max |
||
224 | * |
||
225 | * @return $this |
||
226 | */ |
||
227 | 2 | public function truncate($max = null) |
|
235 | } |
||
236 |