1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2021. Plesk International GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
|
6
|
|
|
use PleskX\Api\Struct\SiteAlias as Struct; |
7
|
|
|
|
8
|
|
|
class SiteAlias extends \PleskX\Api\Operator |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param array $properties |
12
|
|
|
* @param array $preferences |
13
|
|
|
* |
14
|
|
|
* @return Struct\Info |
15
|
|
|
*/ |
16
|
|
|
public function create(array $properties, array $preferences = []) |
17
|
|
|
{ |
18
|
|
|
$packet = $this->_client->getPacket(); |
19
|
|
|
$info = $packet->addChild($this->_wrapperTag)->addChild('create'); |
20
|
|
|
|
21
|
|
|
if (count($preferences) > 0) { |
22
|
|
|
$prefs = $info->addChild('pref'); |
23
|
|
|
|
24
|
|
|
foreach ($preferences as $key => $value) { |
25
|
|
|
$prefs->addChild($key, is_bool($value) ? ($value ? 1 : 0) : $value); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$info->addChild('site-id', $properties['site-id']); |
30
|
|
|
$info->addChild('name', $properties['name']); |
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, 'delete'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $field |
50
|
|
|
* @param int|string $value |
51
|
|
|
* |
52
|
|
|
* @return Struct\GeneralInfo |
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\GeneralInfo[] |
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
|
|
|
$items = []; |
79
|
|
|
foreach ($response->xpath('//result') as $xmlResult) { |
80
|
|
|
$item = new Struct\GeneralInfo($xmlResult->info); |
81
|
|
|
$items[] = $item; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $items; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|