Skip to content

Commit c3e9d91

Browse files
authored
Merge pull request #37 from rybalov/master
Add determining of arrays with duplicate key values
2 parents 8fafa2c + b191a42 commit c3e9d91

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-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

tests/WebspaceTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,78 @@ public function testCreateWebspace()
6161
static::$_client->webspace()->delete('id', $webspace->id);
6262
}
6363

64+
public function testRequestCreateWebspace()
65+
{
66+
$webspace = static::$_client->webspace()->request([
67+
'add' => [
68+
'gen_setup' => [
69+
'name' => 'example-second-test.dom',
70+
'htype' => 'vrt_hst',
71+
'status' => '0',
72+
'ip_address' => [static::_getIpAddress()],
73+
],
74+
'hosting' => [
75+
'vrt_hst' => [
76+
'property' => [
77+
[
78+
'name' => 'php_handler_id',
79+
'value' => 'fastcgi',
80+
],
81+
[
82+
'name' => 'ftp_login',
83+
'value' => 'ftp-login-test-1',
84+
],
85+
[
86+
'name' => 'ftp_password',
87+
'value' => 'ftp-password-test-1',
88+
],
89+
],
90+
'ip_address' => static::_getIpAddress(),
91+
],
92+
],
93+
'limits' => [
94+
'overuse' => 'block',
95+
'limit' => [
96+
[
97+
'name' => 'mbox_quota',
98+
'value' => 100,
99+
],
100+
],
101+
],
102+
'prefs' => [
103+
'www' => 'false',
104+
'stat_ttl' => 6,
105+
],
106+
'performance' => [
107+
'bandwidth' => 120,
108+
'max_connections' => 10000,
109+
],
110+
'permissions' => [
111+
'permission' => [
112+
[
113+
'name' => 'manage_sh_access',
114+
'value' => 'true',
115+
],
116+
],
117+
],
118+
'php-settings' => [
119+
'setting' => [
120+
[
121+
'name' => 'memory_limit',
122+
'value' => '128M',
123+
],
124+
[
125+
'name' => 'safe_mode',
126+
'value' => 'false',
127+
],
128+
],
129+
],
130+
'plan-name' => 'Unlimited',
131+
],
132+
]);
133+
static::$_client->webspace()->delete('id', $webspace->id);
134+
}
135+
64136
public function testDelete()
65137
{
66138
$domain = $this->_createDomain();

0 commit comments

Comments
 (0)