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