Skip to content

Commit 2ea3564

Browse files
authored
Add ServicePlanAddon
1 parent 99e8b97 commit 2ea3564

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

Diff for: src/Api/Operator/ServicePlanAddon.php

+67
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,73 @@
33

44
namespace PleskX\Api\Operator;
55

6+
use PleskX\Api\Struct\ServicePlanAddon as Struct;
7+
68
class ServicePlanAddon extends \PleskX\Api\Operator
79
{
10+
11+
public function create(array $properties): Struct\Info
12+
{
13+
$response = $this->request(['add' => $properties]);
14+
15+
return new Struct\Info($response);
16+
}
17+
18+
/**
19+
* @param string $field
20+
* @param int|string $value
21+
*
22+
* @return bool
23+
*/
24+
public function delete(string $field, $value): bool
25+
{
26+
return $this->deleteBy($field, $value);
27+
}
28+
29+
/**
30+
* @param string $field
31+
* @param int|string $value
32+
*
33+
* @return Struct\Info
34+
*/
35+
public function get(string $field, $value): Struct\Info
36+
{
37+
$items = $this->getBy($field, $value);
38+
39+
return reset($items);
40+
}
41+
42+
/**
43+
* @return Struct\Info[]
44+
*/
45+
public function getAll(): array
46+
{
47+
return $this->getBy();
48+
}
49+
50+
/**
51+
* @param string|null $field
52+
* @param int|string|null $value
53+
*
54+
* @return Struct\Info[]
55+
*/
56+
private function getBy($field = null, $value = null): array
57+
{
58+
$packet = $this->client->getPacket();
59+
$getTag = $packet->addChild($this->wrapperTag)->addChild('get');
60+
61+
$filterTag = $getTag->addChild('filter');
62+
if (!is_null($field)) {
63+
$filterTag->addChild($field, (string) $value);
64+
}
65+
66+
$response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
67+
68+
$items = [];
69+
foreach ($response->xpath('//result') as $xmlResult) {
70+
$items[] = new Struct\Info($xmlResult);
71+
}
72+
73+
return $items;
74+
}
875
}

Diff for: src/Api/Struct/ServicePlanAddon/Info.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
// Copyright 1999-2022. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\ServicePlanAddon;
5+
6+
use PleskX\Api\AbstractStruct;
7+
8+
class Info extends AbstractStruct
9+
{
10+
public int $id;
11+
public string $name;
12+
public string $guid;
13+
public string $externalId;
14+
15+
public function __construct(\SimpleXMLElement $apiResponse)
16+
{
17+
$this->initScalarProperties($apiResponse, [
18+
'id',
19+
'name',
20+
'guid',
21+
'external-id',
22+
]);
23+
}
24+
}

0 commit comments

Comments
 (0)