Skip to content

Commit 5002816

Browse files
author
Nikita Rybalov
committed
Add determining of arrays with duplicate key values
1 parent 8fafa2c commit 5002816

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/PleskX/Api/Client.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,32 @@ protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml)
339339
*
340340
* @param array $array
341341
* @param SimpleXMLElement $xml
342+
* @param string $parentEl
342343
* @return SimpleXMLElement
343344
*/
344-
protected function _arrayToXml(array $array, SimpleXMLElement $xml)
345+
protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl = null)
345346
{
346347
foreach ($array as $key => $value) {
348+
$el = is_int($key) && $parentEl ? $parentEl : $key;
347349
if (is_array($value)) {
348-
$this->_arrayToXml($value, $xml->addChild($key));
350+
$this->_arrayToXml($value, $this->_isAssocArray($value) ? $xml->addChild($el) : $xml, $el);
349351
} else {
350-
$xml->addChild($key, $value);
352+
$xml->addChild($el, $value);
351353
}
352354
}
353355

354356
return $xml;
355357
}
356358

359+
/**
360+
* @param array $array
361+
* @return bool
362+
*/
363+
protected function _isAssocArray(array $array)
364+
{
365+
return $array && array_keys($array) !== range(0, count($array) - 1);
366+
}
367+
357368
/**
358369
* @param string $name
359370
* @return \PleskX\Api\Operator

0 commit comments

Comments
 (0)