1 | <?php |
||
20 | class ArrayMethodCollection extends Collection |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | public function map(callable $callback) |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | public function filter(callable $callback) |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function reduce(callable $callback, $initial = null) |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function each(callable $callback) |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function combine($values, $inPlace = false) |
||
63 | { |
||
64 | if (!is_array($values) && !($values instanceof Traversable)) { |
||
65 | $this->doThrow('Invalid input type for '.($inPlace ? 'replace' : 'combine').'.', $values); |
||
66 | } |
||
67 | |||
68 | // @todo This may change things performance-wise. I had to add this for Traversable $values to work - LV |
||
69 | $values = Factory::getArrayForItems($values); |
||
70 | if (count($values) != count($this->items)) { |
||
71 | $this->doThrow( |
||
72 | 'Invalid input for '.($inPlace ? 'replace' : 'combine').', number of items does not match.', |
||
73 | $values |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | return Factory::create(array_combine($this->items, $values)); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function flip() |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function values() |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function keys() |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function unique() |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function contains($value) |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function merge($items, $inPlace = false) |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function union($items, $inPlace = false) |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function reverse() |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function shift() |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | public function pop() |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | public function chunk($size) |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | public function slice($offset, $length = PHP_INT_MAX) |
||
179 | |||
180 | /** |
||
181 | * {@inheritdoc} |
||
182 | */ |
||
183 | public function diff($items) |
||
187 | |||
188 | /** |
||
189 | * {@inheritdoc} |
||
190 | */ |
||
191 | public function diffKeys($items) |
||
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | public function intersect($items) |
||
203 | |||
204 | /** |
||
205 | * {@inheritdoc} |
||
206 | */ |
||
207 | public function intersectKeys($items) |
||
211 | } |
||
212 |