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