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 mixed 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, int $minCount = 1, int $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 mixed The passed in value |
||
71 | * |
||
72 | * @see in_array() |
||
73 | * |
||
74 | * @throws Exception if $value is not in array $haystack |
||
75 | */ |
||
76 | public static function in($value, array $haystack, bool $strict = true) |
||
86 | |||
87 | /** |
||
88 | * Filter an array by applying filters to each member |
||
89 | * |
||
90 | * @param array $values an array to be filtered. Use the Arrays::filter() before this method to ensure counts when |
||
91 | * you pass into Filterer |
||
92 | * @param array $filters filters with each specified the same as in @see Filterer::filter. |
||
93 | * Eg [['string', false, 2], ['uint']] |
||
94 | * |
||
95 | * @return array the filtered $values |
||
96 | * |
||
97 | * @throws Exception if any member of $values fails filtering |
||
98 | */ |
||
99 | public static function ofScalars(array $values, array $filters) : array |
||
113 | |||
114 | /** |
||
115 | * Filter an array by applying filters to each member |
||
116 | * |
||
117 | * @param array $values as array to be filtered. Use the Arrays::filter() before this method to ensure counts when |
||
118 | * you pass into Filterer |
||
119 | * @param array $spec spec to apply to each $values member, specified the same as in @see Filterer::filter. |
||
120 | * Eg ['key' => ['required' => true, ['string', false], ['unit']], 'key2' => ...] |
||
121 | * |
||
122 | * @return array the filtered $values |
||
123 | * |
||
124 | * @throws Exception if any member of $values fails filtering |
||
125 | */ |
||
126 | public static function ofArrays(array $values, array $spec) : array |
||
151 | |||
152 | /** |
||
153 | * Filter $value by using a Filterer $spec and Filterer's default options. |
||
154 | * |
||
155 | * @param array $value array to be filtered. Use the Arrays::filter() before this method to ensure counts when you |
||
156 | * pass into Filterer |
||
157 | * @param array $spec spec to apply to $value, specified the same as in @see Filterer::filter. |
||
158 | * Eg ['key' => ['required' => true, ['string', false], ['unit']], 'key2' => ...] |
||
159 | * |
||
160 | * @return array the filtered $value |
||
161 | * |
||
162 | * @throws Exception if $value fails filtering |
||
163 | */ |
||
164 | public static function ofArray(array $value, array $spec) : array |
||
173 | |||
174 | /** |
||
175 | * Given a multi-dimensional array, flatten the array to a single level. |
||
176 | * |
||
177 | * The order of the values will be maintained, but the keys will not. |
||
178 | * |
||
179 | * For example, given the array [[1, 2], [3, [4, 5]]], this would result in the array [1, 2, 3, 4, 5]. |
||
180 | * |
||
181 | * @param array $value The array to flatten. |
||
182 | * |
||
183 | * @return array The single-dimension array. |
||
184 | */ |
||
185 | public static function flatten(array $value) : array |
||
198 | } |
||
199 |