1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2019. Plesk International GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
use PleskX\Api\Struct\ServicePlan as Struct; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class ServicePlan extends \PleskX\Api\Operator |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @param string $field |
13
|
|
|
* @param integer|string $value |
14
|
|
|
* @return Struct\Info |
15
|
|
|
*/ |
16
|
|
|
public function get($field, $value) |
17
|
|
|
{ |
18
|
|
|
$items = $this->_get($field, $value); |
19
|
|
|
return reset($items); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return Struct\Info[] |
24
|
|
|
*/ |
25
|
|
|
public function getAll() |
26
|
|
|
{ |
27
|
|
|
return $this->_get(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string|null $field |
32
|
|
|
* @param integer|string|null $value |
33
|
|
|
* @return Struct\Info|Struct\Info[] |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
private function _get($field = null, $value = null) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$packet = $this->_client->getPacket(); |
38
|
|
|
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); |
39
|
|
|
|
40
|
|
|
$filterTag = $getTag->addChild('filter'); |
41
|
|
|
if (!is_null($field)) { |
42
|
|
|
$filterTag->addChild($field, $value); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
46
|
|
|
|
47
|
|
|
$items = []; |
48
|
|
|
foreach ($response->xpath('//result') as $xmlResult) { |
49
|
|
|
$items[] = new Struct\Info($xmlResult); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $items; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $planName |
57
|
|
|
* @return Struct\Info |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function create($planName) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$packet = $this->_client->getPacket(); |
62
|
|
|
$info = $packet->addChild($this->_wrapperTag)->addChild('add'); |
63
|
|
|
$info->addChild('name', $planName); |
64
|
|
|
|
65
|
|
|
$response = $this->_client->request($packet); |
66
|
|
|
return new Struct\Info($response); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $field |
71
|
|
|
* @param integer|string $value |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function delete($field, $value) |
75
|
|
|
{ |
76
|
|
|
return $this->_delete($field, $value); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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.