-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionInterface.php
More file actions
184 lines (163 loc) · 3.8 KB
/
Copy pathCollectionInterface.php
File metadata and controls
184 lines (163 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace Bdf\Prime\Collection;
use Countable;
use ArrayAccess;
use Traversable;
/**
* CollectionInterface
*
* @template E
*
* @extends ArrayAccess<array-key, E>
* @extends Traversable<array-key, E>
*/
interface CollectionInterface extends Countable, ArrayAccess, Traversable
{
public const GROUPBY = 0;
public const GROUPBY_COMBINE = 1;
public const GROUPBY_PRESERVE = 2;
public const GROUPBY_CUSTOM = 3;
/**
* Replace all items
*
* @param E[] $items
*
* @return $this
*/
public function pushAll(array $items);
/**
* Push an item onto the end of the collection.
*
* @param E $item
*
* @return $this
*/
public function push($item);
/**
* Put an item in the collection by key.
*
* @param array-key|null $key
* @param E $item
*
* @return $this
*/
public function put($key, $item);
/**
* Get all of the items in the collection.
*
* @return E[]
*/
public function all();
/**
* Get an item from the collection by key.
*
* @param array-key $key
* @param E|null $default
*
* @return E|null
*/
public function get($key, $default = null);
/**
* Determine if an item exists in the collection by key.
*
* @param array-key $key
* @return bool
*/
public function has($key);
/**
* Remove an item from the collection by key.
*
* @param array-key $key
*
* @return $this
*/
public function remove($key);
/**
* Clear the collection
*
* @return $this
*/
public function clear();
/**
* Get the keys of the collection items.
*
* @return list<array-key>
*/
public function keys();
/**
* Determine if collection is empty
*
* @return boolean
*/
public function isEmpty();
/**
* Runs a callback to every items
*
* @param callable(E):R $callback The function to run
* @return self<R> The new collection
*
* @template R
*/
public function map($callback);
/**
* Filter every entites with a callback
*
* @param callable(E):bool $callback The function to run
* @return static The new filtered collection
*/
public function filter($callback = null);
/**
* Group an associative array by a field or using a callback.
*
* The mode values:
* 0. rebuild on group key,
* 1. combine if group key exist,
* 2. combine and preservee key
* 3. custom injection in the new collection. The callback has to be a callable
*
* @param callable(mixed,array-key,array)|string $groupBy
* @param int $mode
*
* @return self
*
* @throws \LogicException if the mode custom is set and the callback is not a callable
*/
public function groupBy($groupBy, $mode = self::GROUPBY);
/**
* Determine if an item exists in the collection.
*
* @param mixed $element
*
* @return bool
*/
public function contains($element);
/**
* Search the collection for a given value and return the corresponding key if successful.
*
* @param mixed $value
* @param bool $strict
*
* @return array-key|false
*/
public function indexOf($value, $strict = false);
/**
* Merge the collection with the given items.
*
* @param E[]|CollectionInterface<E> $items
* @return self<E>
*/
public function merge($items);
/**
* Sort through each item with a callback.
*
* @param callable|null $callback
* @return self<E>
*/
public function sort(?callable $callback = null);
/**
* Export entity's properties in array
*
* @return E[]
*/
public function toArray();
}