1 | <?php |
||
13 | * Filter an array by throwing if not an array or count not in the min/max range. |
||
14 | * |
||
15 | * The return value is the $value, as expected by the \TraderInteractive\Filterer class. |
||
16 | * |
||
17 | * @param mixed $value the value to filter |
||
18 | * @param int $minCount the minimum allowed count in the array |
||
19 | * @param int $maxCount the maximum allowed count in the array |
||
20 | * |
||
21 | * @return the passed in value |
||
22 | * |
||
23 | * @throws \InvalidArgumentException if $minCount was not an int |
||
24 | * @throws \InvalidArgumentException if $maxCount was not an int |
||
25 | * @throws Exception if $value is not an array |
||
26 | * @throws Exception if $value count is less than $minCount |
||
27 | * @throws Exception if $value count is greater than $maxCount |
||
28 | */ |
||
29 | public static function filter($value, $minCount = 1, $maxCount = PHP_INT_MAX) |
||
60 | |||
61 | /** |
||
62 | * Filter an array by throwing if $value is not in $haystack adhering to $strict. |
||
63 | * |
||
64 | * The return value is the $value, as expected by the \TraderInteractive\Filterer class. |
||
65 | * |
||
66 | * @param mixed $value value to search for |
||
67 | * @param array $haystack array to search in |
||
68 | * @param bool $strict to compare strictly or not. @see in_array() |
||
69 | * |
||
70 | * @return the passed in value |
||
71 | * |
||
72 | * @see in_array() |
||
73 | * @throws \InvalidArgumentException if $strict was not a bool |
||
74 | * @throws Exception if $value is not in array $haystack |
||
75 | */ |
||
76 | public static function in($value, array $haystack, $strict = true) |
||
90 | |||
91 | /** |
||
92 | * Filter an array by applying filters to each member |
||
93 | * |
||
94 | * @param array $values an array to be filtered. Use the Arrays::filter() before this method to ensure counts when |
||
95 | * you pass into Filterer |
||
96 | * @param array $filters filters with each specified the same as in @see Filterer::filter. |
||
97 | * Eg [['string', false, 2], ['uint']] |
||
98 | * |
||
99 | * @return array the filtered $values |
||
100 | * |
||
101 | * @throws Exception if any member of $values fails filtering |
||
102 | */ |
||
103 | public static function ofScalars(array $values, array $filters) |
||
117 | |||
118 | /** |
||
119 | * Filter an array by applying filters to each member |
||
120 | * |
||
121 | * @param array $values as array to be filtered. Use the Arrays::filter() before this method to ensure counts when |
||
122 | * you pass into Filterer |
||
123 | * @param array $spec spec to apply to each $values member, specified the same as in @see Filterer::filter. |
||
124 | * Eg ['key' => ['required' => true, ['string', false], ['unit']], 'key2' => ...] |
||
125 | * |
||
126 | * @return array the filtered $values |
||
127 | * |
||
128 | * @throws Exception if any member of $values fails filtering |
||
129 | */ |
||
130 | public static function ofArrays(array $values, array $spec) |
||
155 | |||
156 | /** |
||
157 | * Filter $value by using a Filterer $spec and Filterer's default options. |
||
158 | * |
||
159 | * @param array $value array to be filtered. Use the Arrays::filter() before this method to ensure counts when you |
||
160 | * pass into Filterer |
||
161 | * @param array $spec spec to apply to $value, specified the same as in @see Filterer::filter. |
||
162 | * Eg ['key' => ['required' => true, ['string', false], ['unit']], 'key2' => ...] |
||
163 | * |
||
164 | * @return array the filtered $value |
||
165 | * |
||
166 | * @throws Exception if $value fails filtering |
||
167 | */ |
||
168 | public static function ofArray(array $value, array $spec) |
||
177 | |||
178 | /** |
||
179 | * Given a multi-dimensional array, flatten the array to a single level. |
||
180 | * |
||
181 | * The order of the values will be maintained, but the keys will not. |
||
182 | * |
||
183 | * For example, given the array [[1, 2], [3, [4, 5]]], this would result in the array [1, 2, 3, 4, 5]. |
||
184 | * |
||
185 | * @param array $value The array to flatten. |
||
186 | * |
||
187 | * @return array The single-dimension array. |
||
188 | */ |
||
189 | public static function flatten(array $value) |
||
202 | } |
||
203 |