@@ -15,31 +15,36 @@ class PrestashopWebService extends PrestashopWebServiceLibrary
15
15
* @return SimpleXMLElement
16
16
* @throws PrestaShopWebserviceException
17
17
*/
18
- public function getSchema ($ resource , $ schema = 'blank ' )
18
+ public function getSchema ($ resource , $ schema = 'blank ' )
19
19
{
20
20
return $ this ->get (['resource ' => $ resource . "?schema= $ schema " ]);
21
21
}
22
22
23
23
/**
24
- * Fill the provided schema with an associative array data, also remove the useless XML nodes if the corresponding flag is true
24
+ * Fill the provided schema with an associative array data, also remove the useless XML nodes if
25
+ * the corresponding flag is true
25
26
*
26
27
* @param SimpleXMLElement $xmlSchema
27
28
* @param array $data
28
29
* @param bool $removeUselessNodes set true if you want to remove nodes that are not present in the data array
29
- * @param array $removeSpecificNodes If $removeUselessNodes is false you may add here the first level nodes that you want to remove
30
+ * @param array $removeSpecificNodes If $removeUselessNodes is false you may add here the first level nodes that
31
+ * you want to remove
30
32
* @return SimpleXMLElement
31
33
*/
32
- public function fillSchema (SimpleXMLElement $ xmlSchema , $ data , $ removeUselessNodes = true , $ removeSpecificNodes =array ())
33
- {
34
+ public function fillSchema (
35
+ SimpleXMLElement $ xmlSchema ,
36
+ $ data ,
37
+ $ removeUselessNodes = true ,
38
+ $ removeSpecificNodes = array ()
39
+ ) {
34
40
$ resource = $ xmlSchema ->children ()->children ();
35
41
foreach ($ data as $ key => $ value ) {
36
42
$ this ->processNode ($ resource , $ key , $ value );
37
43
}
38
44
if ($ removeUselessNodes ) {
39
45
$ this ->checkForUselessNodes ($ resource , $ data );
40
- }
41
- else {
42
- $ this ->removeSpecificNodes ($ resource ,$ removeSpecificNodes );
46
+ } else {
47
+ $ this ->removeSpecificNodes ($ resource , $ removeSpecificNodes );
43
48
}
44
49
return $ xmlSchema ;
45
50
}
@@ -80,13 +85,12 @@ private function fillLanguageNode($node, $data)
80
85
*/
81
86
private function processNode (SimpleXMLElement $ node , $ dataKey , $ dataValue )
82
87
{
83
- if (is_int ($ dataKey )){
84
- if ($ dataKey ===0 ){
88
+ if (is_int ($ dataKey )) {
89
+ if ($ dataKey ===0 ) {
85
90
$ this ->emptyNode ($ node );
86
91
}
87
- $ this ->createNode ($ node ,$ dataValue );
88
- }
89
- elseif (property_exists ($ node ->$ dataKey , 'language ' )) {
92
+ $ this ->createNode ($ node , $ dataValue );
93
+ } elseif (property_exists ($ node ->$ dataKey , 'language ' )) {
90
94
$ this ->fillLanguageNode ($ node ->$ dataKey , $ dataValue );
91
95
} elseif (is_array ($ dataValue )) {
92
96
foreach ($ dataValue as $ key => $ value ) {
@@ -134,17 +138,15 @@ private function removeSpecificNodes($resource, $removeSpecificNodes)
134
138
private function createNode (SimpleXMLElement $ node , $ dataValue )
135
139
{
136
140
foreach ($ dataValue as $ key => $ value ) {
137
- if (is_array ($ value )){
138
- if (is_int ($ key )){
139
- $ this ->createNode ($ node ,$ value );
140
- }
141
- else {
141
+ if (is_array ($ value )) {
142
+ if (is_int ($ key )) {
143
+ $ this ->createNode ($ node , $ value );
144
+ } else {
142
145
$ childNode =$ node ->addChild ($ key );
143
- $ this ->createNode ($ childNode ,$ value );
146
+ $ this ->createNode ($ childNode , $ value );
144
147
}
145
- }
146
- else {
147
- $ node ->addChild ($ key ,$ value );
148
+ } else {
149
+ $ node ->addChild ($ key , $ value );
148
150
}
149
151
}
150
152
}
@@ -162,4 +164,4 @@ private function emptyNode(SimpleXMLElement $node)
162
164
unset($ node ->$ nodeName );
163
165
}
164
166
}
165
- }
167
+ }
0 commit comments