1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2016. Parallels IP Holdings GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
use PleskX\Api\Struct\Site as Struct; |
6
|
|
|
|
7
|
|
|
class Site extends \PleskX\Api\Operator |
8
|
|
|
{ |
9
|
|
|
const PROPERTIES_HOSTING = 'hosting'; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @param array $properties |
13
|
|
|
* @return Struct\Info |
14
|
|
|
*/ |
15
|
|
|
public function create(array $properties) |
16
|
|
|
{ |
17
|
|
|
$packet = $this->_client->getPacket(); |
18
|
|
|
$info = $packet->addChild($this->_wrapperTag)->addChild('add'); |
19
|
|
|
|
20
|
|
|
$infoGeneral = $info->addChild('gen_setup'); |
21
|
|
|
foreach ($properties as $name => $value) { |
22
|
|
|
if (!is_scalar($value)) { |
23
|
|
|
continue; |
24
|
|
|
} |
25
|
|
|
$infoGeneral->addChild($name, $value); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
// set hosting properties |
29
|
|
|
if (isset($properties[static::PROPERTIES_HOSTING]) && is_array($properties[static::PROPERTIES_HOSTING])) { |
30
|
|
|
$hostingNode = $info->addChild('hosting')->addChild('vrt_hst'); |
31
|
|
|
foreach ($properties[static::PROPERTIES_HOSTING] as $name => $value) { |
32
|
|
|
$propertyNode = $hostingNode->addChild('property'); |
33
|
|
|
$propertyNode->addChild('name', $name); |
34
|
|
|
$propertyNode->addChild('value', $value); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$response = $this->_client->request($packet); |
39
|
|
|
return new Struct\Info($response); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $field |
44
|
|
|
* @param integer|string $value |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
public function delete($field, $value) |
48
|
|
|
{ |
49
|
|
|
return $this->_delete($field, $value); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $field |
54
|
|
|
* @param integer|string $value |
55
|
|
|
* @return Struct\GeneralInfo |
56
|
|
|
*/ |
57
|
|
|
public function get($field, $value) |
58
|
|
|
{ |
59
|
|
|
$items = $this->_getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value); |
60
|
|
|
return reset($items); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $field |
65
|
|
|
* @param integer|string $value |
66
|
|
|
* @return Struct\HostingInfo|null |
67
|
|
|
*/ |
68
|
|
|
public function getHosting($field, $value) |
69
|
|
|
{ |
70
|
|
|
$items = $this->_getItems(Struct\HostingInfo::class, 'hosting', $field, $value, function ($node) { |
71
|
|
|
return isset($node->vrt_hst); |
72
|
|
|
}); |
73
|
|
|
return empty($items) ? null : reset($items); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return Struct\GeneralInfo[] |
78
|
|
|
*/ |
79
|
|
|
public function getAll() |
80
|
|
|
{ |
81
|
|
|
return $this->_getItems(Struct\GeneralInfo::class, 'gen_info'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|