1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2016. Parallels IP Holdings GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
use PleskX\Api\Struct\Database as Struct; |
6
|
|
|
|
7
|
|
|
class Database extends \PleskX\Api\Operator |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param array $properties |
11
|
|
|
* @return Struct\ShortInfo |
12
|
|
|
*/ |
13
|
|
|
public function create($properties) |
14
|
|
|
{ |
15
|
|
|
$packet = $this->_client->getPacket(); |
16
|
|
|
$info = $packet->addChild($this->_wrapperTag)->addChild('add-db'); |
17
|
|
|
|
18
|
|
|
foreach ($properties as $name => $value) { |
19
|
|
|
$info->addChild($name, $value); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
$response = $this->_client->request($packet); |
23
|
|
|
return new Struct\ShortInfo($response); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $field |
28
|
|
|
* @param integer|string $value |
29
|
|
|
* @return Struct\Info[] |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
public function get($field, $value) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$packet = $this->_client->getPacket(); |
34
|
|
|
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get-db'); |
35
|
|
|
|
36
|
|
|
$filterTag = $getTag->addChild('filter'); |
37
|
|
|
if (!is_null($field)) { |
38
|
|
|
$filterTag->addChild($field, $value); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
42
|
|
|
|
43
|
|
|
$items = []; |
44
|
|
|
foreach ( $response->xpath('//result')as $xmlResult) { |
45
|
|
|
$items[] = new Struct\Info($xmlResult); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $items; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $field |
53
|
|
|
* @param integer|string $value |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function delete($field, $value) |
57
|
|
|
{ |
58
|
|
|
return $this->_delete($field, $value, 'del-db'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.