1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2016. Parallels IP Holdings GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api; |
5
|
|
|
|
6
|
|
|
class Operator |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** @var string|null */ |
10
|
|
|
protected $_wrapperTag = null; |
11
|
|
|
|
12
|
|
|
/** @var \PleskX\Api\Client */ |
13
|
|
|
protected $_client; |
14
|
|
|
|
15
|
|
|
public function __construct($client) |
16
|
|
|
{ |
17
|
|
|
$this->_client = $client; |
18
|
|
|
|
19
|
|
|
if (is_null($this->_wrapperTag)) { |
20
|
|
|
$classNameParts = explode('\\', get_class($this)); |
21
|
|
|
$this->_wrapperTag = end($classNameParts); |
22
|
|
|
$this->_wrapperTag = strtolower(preg_replace('/([a-z])([A-Z])/', '\1-\2', $this->_wrapperTag)); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Perform plain API request |
28
|
|
|
* |
29
|
|
|
* @param string|array $request |
30
|
|
|
* @param int $mode |
31
|
|
|
* @return XmlResponse |
32
|
|
|
*/ |
33
|
|
|
public function request($request, $mode = Client::RESPONSE_SHORT) |
34
|
|
|
{ |
35
|
|
|
$wrapperTag = $this->_wrapperTag; |
36
|
|
|
|
37
|
|
|
if (is_array($request)) { |
38
|
|
|
$request = [$wrapperTag => $request]; |
39
|
|
|
} else if (preg_match('/^[a-z]/', $request)) { |
40
|
|
|
$request = "$wrapperTag.$request"; |
41
|
|
|
} else { |
42
|
|
|
$request = "<$wrapperTag>$request</$wrapperTag>"; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $this->_client->request($request, $mode); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $field |
50
|
|
|
* @param integer|string $value |
51
|
|
|
* @param string $deleteMethodName |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
|
|
public function _delete($field, $value, $deleteMethodName = 'del') |
55
|
|
|
{ |
56
|
|
|
$response = $this->request("$deleteMethodName.filter.$field=$value"); |
57
|
|
|
return 'ok' === (string)$response->status; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|