|
3 | 3 |
|
4 | 4 | namespace PleskX\Api\Operator; |
5 | 5 |
|
| 6 | +use PleskX\Api\Struct\ServicePlanAddon as Struct; |
| 7 | + |
6 | 8 | class ServicePlanAddon extends \PleskX\Api\Operator |
7 | 9 | { |
| 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 | + } |
8 | 75 | } |
0 commit comments