Skip to content

Commit

Permalink
Merge pull request #109 from plesk/bugfix-vdiomidov-simplexml-amprsan…
Browse files Browse the repository at this point in the history
…t-fix-ppp-54497

BUGFIX EXTREST-137 simpleXml fix for & in values
  • Loading branch information
xgin authored Oct 6, 2021
2 parents 8ad7345 + 21ecea0 commit f226ce3
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 30 deletions.
9 changes: 7 additions & 2 deletions src/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,15 @@ protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml)
{
$parts = explode('.', $request);
$node = $xml;
$lastParts = end($parts);

foreach ($parts as $part) {
@list($name, $value) = explode('=', $part);
$node = $node->addChild($name, $value);
if ($part !== $lastParts) {
$node = $node->addChild($name);
} else {
$node->{$name} = (string) $value;
}
}

return $xml->asXML();
Expand All @@ -346,7 +351,7 @@ protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl =
if (is_array($value)) {
$this->_arrayToXml($value, $this->_isAssocArray($value) ? $xml->addChild($el) : $xml, $el);
} else {
$xml->addChild($el, $value);
$xml->{$el} = (string) $value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function _getItems($structClass, $infoTag, $field = null, $value = nul

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, $value);
$filterTag->{$field} = $value;
}

$getTag->addChild('dataset')->addChild($infoTag);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function generate($properties)
$info = $packet->addChild($this->_wrapperTag)->addChild('generate')->addChild('info');

foreach ($properties as $name => $value) {
$info->addChild($name, $value);
$info->{$name} = $value;
}

$response = $this->_client->request($packet);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function create($properties)
$info = $packet->addChild($this->_wrapperTag)->addChild('add')->addChild('gen_info');

foreach ($properties as $name => $value) {
$info->addChild($name, $value);
$info->{$name} = $value;
}

$response = $this->_client->request($packet);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Operator/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function _process($command, array $properties)
$info->$name = $value;
continue;
}
$info->addChild($name, $value);
$info->{$name} = $value;
}

return $this->_client->request($packet);
Expand Down Expand Up @@ -135,7 +135,7 @@ private function _get($command, $field, $value)

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, $value);
$filterTag->{$field} = $value;
}

$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/DatabaseServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function _get($field = null, $value = null)

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, $value);
$filterTag->{$field} = $value;
}

$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Operator/Dns.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function create($properties)
$info = $packet->addChild($this->_wrapperTag)->addChild('add_rec');

foreach ($properties as $name => $value) {
$info->addChild($name, $value);
$info->{$name} = $value;
}

return new Struct\Info($this->_client->request($packet));
Expand All @@ -39,7 +39,7 @@ public function bulkCreate(array $records)
$info = $packet->addChild($this->_wrapperTag)->addChild('add_rec');

foreach ($properties as $name => $value) {
$info->addChild($name, $value);
$info->{$name} = $value;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Api/Operator/DnsTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function create(array $properties)

unset($properties['site-id'], $properties['site-alias-id']);
foreach ($properties as $name => $value) {
$info->addChild($name, $value);
$info->{$name} = $value;
}

return new Struct\Info($this->_client->request($packet));
Expand Down Expand Up @@ -53,7 +53,7 @@ public function getAll($field = null, $value = null)

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, $value);
$filterTag->{$field} = $value;
}
$getTag->addChild('template');

Expand Down
4 changes: 2 additions & 2 deletions src/Api/Operator/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function create($name, $siteId, $mailbox = false, $password = '')
$mailname->addChild('mailbox')->addChild('enabled', 'true');
}
if (!empty($password)) {
$mailname->addChild('password')->addChild('value', $password);
$mailname->addChild('password')->value = $password;
}

$response = $this->_client->request($packet);
Expand All @@ -48,7 +48,7 @@ public function delete($field, $value, $siteId)
$packet = $this->_client->getPacket();
$filter = $packet->addChild($this->_wrapperTag)->addChild('remove')->addChild('filter');
$filter->addChild('site-id', $siteId);
$filter->addChild($field, $value);
$filter->{$field} = $value;
$response = $this->_client->request($packet);

return 'ok' === (string) $response->status;
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Operator/ProtectedDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public function addUser($protectedDirectory, $login, $password)
$packet = $this->_client->getPacket();
$info = $packet->addChild($this->_wrapperTag)->addChild('add-user');

$info->addChild('pd-id', $protectedDirectory->id);
$info->addChild('login', $login);
$info->addChild('password', $password);
$info->{'pd-id'} = $protectedDirectory->id;
$info->login = $login;
$info->password = $password;

return new Struct\UserInfo($this->_client->request($packet));
}
Expand Down Expand Up @@ -113,7 +113,7 @@ private function _get($command, $field, $value)

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, $value);
$filterTag->{$field} = $value;
}

$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/Reseller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function create($properties)
$info = $packet->addChild($this->_wrapperTag)->addChild('add')->addChild('gen-info');

foreach ($properties as $name => $value) {
$info->addChild($name, $value);
$info->{$name} = $value;
}

$response = $this->_client->request($packet);
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Operator/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public function create(array $properties)
if (!is_scalar($value)) {
continue;
}
$infoGeneral->addChild($name, $value);
$infoGeneral->{$name} = $value;
}

// set hosting properties
if (isset($properties[static::PROPERTIES_HOSTING]) && is_array($properties[static::PROPERTIES_HOSTING])) {
$hostingNode = $info->addChild('hosting')->addChild('vrt_hst');
foreach ($properties[static::PROPERTIES_HOSTING] as $name => $value) {
$propertyNode = $hostingNode->addChild('property');
$propertyNode->addChild('name', $name);
$propertyNode->addChild('value', $value);
$propertyNode->name = $name;
$propertyNode->value = $value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/SiteAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getAll($field = null, $value = null)

$filterTag = $getTag->addChild('filter');
if (!is_null($field)) {
$filterTag->addChild($field, $value);
$filterTag->{$field} = $value;
}

$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Operator/Subdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function create($properties)
if (is_array($value)) {
foreach ($value as $propertyName => $propertyValue) {
$property = $info->addChild($name);
$property->addChild('name', $propertyName);
$property->addChild('value', $propertyValue);
$property->name = $propertyName;
$property->value = $propertyValue;
}
continue;
}
$info->addChild($name, $value);
$info->{$name} = $value;
}

$response = $this->_client->request($packet);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/Ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function createCustomButton($owner, $properties)
$propertiesNode = $buttonNode->addChild('properties');

foreach ($properties as $name => $value) {
$propertiesNode->addChild($name, $value);
$propertiesNode->{$name} = $value;
}

$response = $this->_client->request($packet);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Operator/Webspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function create(array $properties, array $hostingProperties = null, strin
$infoHosting = $info->addChild('hosting')->addChild('vrt_hst');
foreach ($hostingProperties as $name => $value) {
$property = $infoHosting->addChild('property');
$property->addChild('name', $name);
$property->addChild('value', $value);
$property->name = $name;
$property->value = $value;
}

if (isset($properties['ip_address'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Utility/PasswordProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

class PasswordProvider
{
const STRONG_PASSWORD = 'test-PWD*1@42!13#';
const STRONG_PASSWORD = 'test-&PWD*1@42!13#';
}

0 comments on commit f226ce3

Please sign in to comment.