|
@@ -0,0 +1,43 @@
|
|
1
|
+<?php
|
|
2
|
+/**
|
|
3
|
+ * Created by PhpStorm.
|
|
4
|
+ * User: robin
|
|
5
|
+ * Date: 1/10/16
|
|
6
|
+ * Time: 11:28 PM
|
|
7
|
+ */
|
|
8
|
+
|
|
9
|
+namespace Luticate\Utils;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+class LuStringUtils
|
|
13
|
+{
|
|
14
|
+ public static function stringSnakeToCamelCase($string, $capitalizeFirstCharacter) {
|
|
15
|
+ $str = preg_replace_callback("/_[a-zA-Z]/", function($matches)
|
|
16
|
+ {
|
|
17
|
+ return strtoupper($matches[0][1]);
|
|
18
|
+ }, $string);
|
|
19
|
+ if ($capitalizeFirstCharacter)
|
|
20
|
+ $str[0] = strtoupper($str[0]);
|
|
21
|
+ return $str;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ public static function arraySnakeToCamelCase($array)
|
|
25
|
+ {
|
|
26
|
+ if (!is_array($array))
|
|
27
|
+ {
|
|
28
|
+ return $array;
|
|
29
|
+ }
|
|
30
|
+ $camelCase = [];
|
|
31
|
+ foreach ($array as $key => $value)
|
|
32
|
+ {
|
|
33
|
+ $camelCase[self::stringSnakeToCamelCase($key, true)] = self::arraySnakeToCamelCase($value);
|
|
34
|
+ }
|
|
35
|
+ return $camelCase;
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ public static function convertJsonString($json)
|
|
39
|
+ {
|
|
40
|
+ $array = json_decode($json, true);
|
|
41
|
+ return self::arraySnakeToCamelCase($array);
|
|
42
|
+ }
|
|
43
|
+}
|