From 2ea3564fc5c99a048d401102c3eb7551b3228c2e Mon Sep 17 00:00:00 2001 From: David H <50745202+DavidHDJ@users.noreply.github.com> Date: Sat, 22 Apr 2023 15:48:58 +0200 Subject: [PATCH] Add ServicePlanAddon --- src/Api/Operator/ServicePlanAddon.php | 67 ++++++++++++++++++++++++ src/Api/Struct/ServicePlanAddon/Info.php | 24 +++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/Api/Struct/ServicePlanAddon/Info.php diff --git a/src/Api/Operator/ServicePlanAddon.php b/src/Api/Operator/ServicePlanAddon.php index 7eee5799..8cb5a965 100644 --- a/src/Api/Operator/ServicePlanAddon.php +++ b/src/Api/Operator/ServicePlanAddon.php @@ -3,6 +3,73 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\ServicePlanAddon as Struct; + class ServicePlanAddon extends \PleskX\Api\Operator { + + public function create(array $properties): Struct\Info + { + $response = $this->request(['add' => $properties]); + + return new Struct\Info($response); + } + + /** + * @param string $field + * @param int|string $value + * + * @return bool + */ + public function delete(string $field, $value): bool + { + return $this->deleteBy($field, $value); + } + + /** + * @param string $field + * @param int|string $value + * + * @return Struct\Info + */ + public function get(string $field, $value): Struct\Info + { + $items = $this->getBy($field, $value); + + return reset($items); + } + + /** + * @return Struct\Info[] + */ + public function getAll(): array + { + return $this->getBy(); + } + + /** + * @param string|null $field + * @param int|string|null $value + * + * @return Struct\Info[] + */ + private function getBy($field = null, $value = null): array + { + $packet = $this->client->getPacket(); + $getTag = $packet->addChild($this->wrapperTag)->addChild('get'); + + $filterTag = $getTag->addChild('filter'); + if (!is_null($field)) { + $filterTag->addChild($field, (string) $value); + } + + $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); + + $items = []; + foreach ($response->xpath('//result') as $xmlResult) { + $items[] = new Struct\Info($xmlResult); + } + + return $items; + } } diff --git a/src/Api/Struct/ServicePlanAddon/Info.php b/src/Api/Struct/ServicePlanAddon/Info.php new file mode 100644 index 00000000..4ec2bd78 --- /dev/null +++ b/src/Api/Struct/ServicePlanAddon/Info.php @@ -0,0 +1,24 @@ +initScalarProperties($apiResponse, [ + 'id', + 'name', + 'guid', + 'external-id', + ]); + } +}