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