1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2021. Plesk International GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
|
6
|
|
|
use PleskX\Api\Struct\ServicePlan as Struct; |
7
|
|
|
|
8
|
|
|
class ServicePlan extends \PleskX\Api\Operator |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param array $properties |
12
|
|
|
* @return Struct\Info |
13
|
|
|
*/ |
14
|
|
|
public function create($properties) |
15
|
|
|
{ |
16
|
|
|
$response = $this->request(['add' => $properties]); |
17
|
|
|
return new Struct\Info($response); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param string $field |
22
|
|
|
* @param int|string $value |
23
|
|
|
* @return bool |
24
|
|
|
*/ |
25
|
|
|
public function delete($field, $value) |
26
|
|
|
{ |
27
|
|
|
return $this->_delete($field, $value); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $field |
32
|
|
|
* @param int|string $value |
33
|
|
|
* |
34
|
|
|
* @return Struct\Info |
35
|
|
|
*/ |
36
|
|
|
public function get($field, $value) |
37
|
|
|
{ |
38
|
|
|
$items = $this->_get($field, $value); |
39
|
|
|
|
40
|
|
|
return reset($items); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return Struct\Info[] |
45
|
|
|
*/ |
46
|
|
|
public function getAll() |
47
|
|
|
{ |
48
|
|
|
return $this->_get(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string|null $field |
53
|
|
|
* @param int|string|null $value |
54
|
|
|
* |
55
|
|
|
* @return Struct\Info|Struct\Info[] |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
private function _get($field = null, $value = null) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$packet = $this->_client->getPacket(); |
60
|
|
|
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); |
61
|
|
|
|
62
|
|
|
$filterTag = $getTag->addChild('filter'); |
63
|
|
|
if (!is_null($field)) { |
64
|
|
|
$filterTag->addChild($field, $value); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
68
|
|
|
|
69
|
|
|
$items = []; |
70
|
|
|
foreach ($response->xpath('//result') as $xmlResult) { |
71
|
|
|
$items[] = new Struct\Info($xmlResult); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $items; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.