1 | <?php |
||
7 | class PrestashopWebService extends PrestashopWebServiceLibrary |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Retrieve the resource schema |
||
12 | * |
||
13 | * @param $resource |
||
14 | * @param string $schema |
||
15 | * @return SimpleXMLElement |
||
16 | * @throws Exceptions\PrestashopWebServiceException |
||
17 | */ |
||
18 | public function getSchema($resource, $schema = 'blank') |
||
22 | |||
23 | /** |
||
24 | * Fill the provided schema with an associative array data, also remove the useless XML nodes if |
||
25 | * the corresponding flag is true |
||
26 | * |
||
27 | * @param SimpleXMLElement $xmlSchema |
||
28 | * @param array $data |
||
29 | * @param bool $removeUselessNodes set true if you want to remove nodes that are not present in the data array |
||
30 | * @param array $removeSpecificNodes If $removeUselessNodes is false you may add here the first level nodes that |
||
31 | * you want to remove |
||
32 | * @return SimpleXMLElement |
||
33 | */ |
||
34 | public function fillSchema( |
||
51 | |||
52 | /** |
||
53 | * @param string|array $data |
||
54 | * @param $languageId |
||
55 | * @return string |
||
56 | */ |
||
57 | private function getLanguageValue($data, $languageId) |
||
69 | |||
70 | /** |
||
71 | * @param $node |
||
72 | * @param $data |
||
73 | */ |
||
74 | private function fillLanguageNode($node, $data) |
||
80 | |||
81 | /** |
||
82 | * @param SimpleXMLElement $node |
||
83 | * @param $dataKey |
||
84 | * @param $dataValue |
||
85 | */ |
||
86 | private function processNode(SimpleXMLElement $node, $dataKey, $dataValue) |
||
103 | |||
104 | /** |
||
105 | * Remove XML first level nodes that are not present int the data array |
||
106 | * @param SimpleXMLElement $resource |
||
107 | * @param $data |
||
108 | */ |
||
109 | private function checkForUselessNodes(SimpleXMLElement $resource, $data) |
||
122 | |||
123 | /** |
||
124 | * Remove the given nodes from the resource |
||
125 | * @param $resource |
||
126 | * @param $removeSpecificNodes |
||
127 | */ |
||
128 | private function removeSpecificNodes($resource, $removeSpecificNodes) |
||
134 | |||
135 | /** |
||
136 | * @param SimpleXMLElement $node |
||
137 | * @param array $dataValue |
||
138 | */ |
||
139 | private function createNode(SimpleXMLElement $node, $dataValue) |
||
154 | |||
155 | /** |
||
156 | * @param SimpleXMLElement $node |
||
157 | */ |
||
158 | private function emptyNode(SimpleXMLElement $node) |
||
169 | } |
||
170 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: