This repository was archived by the owner on Jul 10, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Sober \Controller \Module ;
4
4
5
+ use Sober \Controller \Utils ;
6
+
5
7
class Acf
6
8
{
7
9
// Config
@@ -32,6 +34,21 @@ private function setReturnFilter()
32
34
: false );
33
35
}
34
36
37
+ /**
38
+ * Recursively iterates over array and adds a new snake cased keys=>value for all kebab cased keys
39
+ *
40
+ * Return void
41
+ */
42
+ private function recursiveSnakeCase (&$ data ) {
43
+ foreach ($ data as $ key => $ val ) {
44
+ if (is_array ($ val )) {
45
+ $ this ->recursiveSnakeCase ($ val );
46
+ } else {
47
+ $ data [Utils::convertKebabCaseToSnakeCase ($ key )] = $ val ;
48
+ }
49
+ }
50
+ }
51
+
35
52
/**
36
53
* Set Data Return Format
37
54
*
@@ -88,6 +105,8 @@ public function setData($acf)
88
105
$ this ->data [$ item ] = get_field ($ item , $ query );
89
106
}
90
107
}
108
+
109
+ $ this ->recursiveSnakeCase ($ this ->data );
91
110
}
92
111
93
112
/**
Original file line number Diff line number Diff line change @@ -69,4 +69,15 @@ public static function convertToKebabCase($str)
69
69
{
70
70
return strtolower (preg_replace ('/(?<!^)[A-Z]/ ' , '-$0 ' , $ str ));
71
71
}
72
+
73
+ /**
74
+ * Convert To Snake Case
75
+ *
76
+ * Converts kebab case to snake case for data variables
77
+ * @return string
78
+ */
79
+ public static function convertKebabCaseToSnakeCase ($ str )
80
+ {
81
+ return strtolower (str_replace ('- ' , '_ ' , $ str ));
82
+ }
72
83
}
You can’t perform that action at this time.
0 commit comments