@@ -29,23 +29,10 @@ public function getSchema($resource)
29
29
*/
30
30
public function fillSchema (SimpleXMLElement $ xmlSchema , $ data )
31
31
{
32
- $ toBeRemoved = array ();
33
32
$ resource = $ xmlSchema ->children ()->children ();
34
- foreach ($ resource as $ key => $ value ) {
35
- if (array_key_exists ($ key , $ data )) {
36
- if (property_exists ($ resource ->$ key , 'language ' )) {
37
- $ this ->fillLanguageNode ($ resource ->$ key , $ data [$ key ]);
38
- } else {
39
- $ resource ->$ key = $ data [$ key ];
40
- }
41
- } else {
42
- $ toBeRemoved [] = $ key ;
43
- }
44
- }
45
- foreach ($ toBeRemoved as $ key ) {
46
- unset($ resource ->$ key );
33
+ foreach ($ data as $ key => $ value ) {
34
+ $ this ->processNode ($ resource , $ key , $ value );
47
35
}
48
-
49
36
return $ xmlSchema ;
50
37
}
51
38
@@ -77,4 +64,22 @@ private function fillLanguageNode($node, $data)
77
64
$ node ->language [$ i ] = $ this ->getLanguageValue ($ data , (int )$ node ->language [$ i ]['id ' ]->__toString ());
78
65
}
79
66
}
67
+
68
+ /**
69
+ * @param SimpleXMLElement $node
70
+ * @param $dataKey
71
+ * @param $dataValue
72
+ */
73
+ private function processNode (SimpleXMLElement $ node , $ dataKey , $ dataValue )
74
+ {
75
+ if (property_exists ($ node ->$ dataKey , 'language ' )) {
76
+ $ this ->fillLanguageNode ($ node ->$ dataKey , $ dataValue );
77
+ } elseif (is_array ($ dataValue )) {
78
+ foreach ($ dataValue as $ key => $ value ) {
79
+ $ this ->processNode ($ node ->$ dataKey , $ key , $ value );
80
+ }
81
+ } else {
82
+ $ node ->$ dataKey = $ dataValue ;
83
+ }
84
+ }
80
85
}
0 commit comments