1 | <?php |
||
8 | class Mappings |
||
9 | { |
||
10 | /** |
||
11 | * Returns a closure that strips any matching $chars from the left of the input string |
||
12 | * |
||
13 | * @param string $chars |
||
14 | * @return \Closure |
||
15 | */ |
||
16 | 5 | public static function lstrip($chars = " \t\n\r\0\x0B") |
|
22 | |||
23 | /** |
||
24 | * Returns a closure that strips any matching $chars from the right of the input string |
||
25 | * |
||
26 | * @param string $chars |
||
27 | * @return \Closure |
||
28 | */ |
||
29 | 5 | public static function rstrip($chars = " \t\n\r\0\x0B") |
|
35 | |||
36 | /** |
||
37 | * Returns a closure that strips any matching $chars from the left and right of the input string |
||
38 | * |
||
39 | * @param string $chars |
||
40 | * @return \Closure |
||
41 | */ |
||
42 | 6 | public static function strip($chars = " \t\n\r\0\x0B") |
|
48 | |||
49 | /** |
||
50 | * Returns a closure that returns the length of the input |
||
51 | * |
||
52 | * @return \Closure |
||
53 | */ |
||
54 | 3 | public static function length() |
|
66 | |||
67 | /** |
||
68 | * Returns a closure that returns the key |
||
69 | * |
||
70 | * @return \Closure |
||
71 | */ |
||
72 | 5 | public static function key() |
|
78 | |||
79 | /** |
||
80 | * Returns a closure that returns the string value lower cased |
||
81 | * |
||
82 | * @return \Closure |
||
83 | */ |
||
84 | 1 | public static function lower() |
|
90 | |||
91 | /** |
||
92 | * Returns a closure that returns the string value upper cased |
||
93 | * |
||
94 | * @return \Closure |
||
95 | */ |
||
96 | 1 | public static function upper() |
|
102 | |||
103 | /** |
||
104 | * Returns a closure that returns the value cast to a string |
||
105 | * |
||
106 | * @return \Closure |
||
107 | */ |
||
108 | 1 | public static function string() |
|
114 | |||
115 | /** |
||
116 | * Returns a closure that returns the value as a json_encoded string |
||
117 | * |
||
118 | * @param int $options |
||
119 | * @param int $depth |
||
120 | * @return \Closure |
||
121 | */ |
||
122 | 1 | public static function jsonEncode($options = 0, $depth = 512) |
|
128 | |||
129 | /** |
||
130 | * Returns a closure that returns the json_encoded value as decoded value |
||
131 | * |
||
132 | * @param boolean $associative |
||
133 | * @param int $options |
||
134 | * @param int $depth |
||
135 | * @return \Closure |
||
136 | */ |
||
137 | 1 | public static function jsonDecode($associative = false, $options = 0, $depth = 512) |
|
143 | |||
144 | /** |
||
145 | * Returns a closure that applies multiple mappings to the value and returns the results |
||
146 | * |
||
147 | * > $compute = function ($value, $key) { |
||
148 | * > return 'some computation result'; |
||
149 | * > }; |
||
150 | * > $list = iterable([new Data(1), new Data(2), new Data(3)]); |
||
151 | * > $list->map(Mappings::select(['data' => null, 'id' => 'Identifier', 'desc' => 'Value.DescriptionName', 'comp' => $compute])); |
||
152 | * [ |
||
153 | * [ |
||
154 | * 'data' => Data(1), |
||
155 | * 'id' => Data(1)->Identifier, |
||
156 | * 'desc' => Data(1)->Value->DescriptionName, |
||
157 | * 'comp' => $compute(Data(1), 0), |
||
158 | * ], |
||
159 | * ... |
||
160 | * [ |
||
161 | * 'data' => Data(3), |
||
162 | * 'id' => Data(3)->Identifier, |
||
163 | * 'desc' => Data(3)->Value->DescriptionName, |
||
164 | * 'comp' => $compute(Data(3), 2), |
||
165 | * ], |
||
166 | * ] |
||
167 | * |
||
168 | * @param array|object $mappings |
||
169 | * @param null|string|\Closure $strategy |
||
170 | * @param boolean $discardNull |
||
171 | * @param boolean $discardEmptyContainer |
||
172 | * @return \Closure |
||
173 | */ |
||
174 | 9 | public static function select($mappings, $strategy = null, $discardNull = false, $discardEmptyContainer = false) |
|
205 | |||
206 | /** |
||
207 | * Returns a closure that returns random integer numbers between $MIN and $MAX |
||
208 | * |
||
209 | * @param int $min |
||
210 | * @param null|int $max |
||
211 | * @return \Closure |
||
212 | */ |
||
213 | 5 | public static function random($min = 0, $max = null) |
|
223 | |||
224 | /** |
||
225 | * Returns a closure that returns either the class name, given an object, or otherwise the type |
||
226 | * |
||
227 | * @param null|string|\Closure $strategy |
||
228 | * @return \Closure |
||
229 | */ |
||
230 | 6 | public static function type($strategy = null) |
|
238 | |||
239 | /** |
||
240 | * Returns a closure that calls the mapping on each element once. |
||
241 | * |
||
242 | * > $compute = function ($value, $key) { |
||
243 | * > return 'some expensive computation result'; |
||
244 | * > }; |
||
245 | * > $list = iterable([['id' => 42, ...], ['id' => 43, ...], ['id' => 42, ...]]); |
||
246 | * > $list->map(Mappings::cache($compute, 'id')); |
||
247 | * [ |
||
248 | * $compute(['id' => 42, ...]), // <-- calls the $compute method |
||
249 | * $compute(['id' => 43, ...]), // <-- calls the $compute method |
||
250 | * $compute(['id' => 42, ...]) // <-- does not call, instead, populates with cached values |
||
251 | * ] |
||
252 | * |
||
253 | * @param null|string|\Closure $mapping |
||
254 | * @param null|string|\Closure $strategy |
||
255 | * @return \Closure |
||
256 | */ |
||
257 | 2 | public static function cache($mapping, $strategy = null) |
|
270 | |||
271 | /** |
||
272 | * Returns a closure that returns the same value every time it is called. |
||
273 | * |
||
274 | * @param null|string|int|float|bool|object|array $value |
||
275 | * @return \Closure |
||
276 | */ |
||
277 | public static function constant($value) |
||
283 | |||
284 | /** |
||
285 | * @param string $name |
||
286 | * @return \Closure |
||
287 | * @deprecated will be removed in version 3.0 |
||
288 | */ |
||
289 | public static function getMapping($name /* [argument, [arguments, ...] */) |
||
311 | } |
||
312 |